首页 > 编程语言 > 详细

python

时间:2015-05-24 06:29:52      阅读:271      评论:0      收藏:0      [点我收藏+]
import os

def rename_file():
    file_name_list=os.listdir(r"/Users/Lily/Documents/ASU1/CodePractise/prank")
    print(file_name_list)
    saved_path=os.getcwd()
    print("current working directory is"+saved_path)
    os.chdir(r"/Users/Lily/Documents/ASU1/CodePractise/prank")
    for file_name in file_name_list:
        os.rename(file_name, file_name.translate(None, "0123456789"))
    os.chdir(saved_path)

rename_file()

  os: Miscellaneous operating system interfaces

os.listdir(path):

Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries ‘.‘ and ‘..‘ even if they are present in the directory.

Availability: Unix, Windows.

os.getcwd(): Return a string representing the current working directory.

os.chdir(path):Change the current working directory to path.

python string translate():

str.translate(table[, deletechars]);

Parameters

  • table -- You can use the maketrans() helper function in the string module to create a translation table.

  • deletechars -- The list of characters to be removed from the source string.

 

 

python

原文:http://www.cnblogs.com/lilyfindjobs/p/4525305.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!