标签:
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]);
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.
标签:
原文地址:http://www.cnblogs.com/lilyfindjobs/p/4525305.html