这可以通过python实现,但我认为我缺少一种循环所有目录的方法。以下是我正在使用的代码:
import os
def renameInDir(directory):
for filename in os.listdir(directory):
if filename.endswith(".pdf"):
path = os.path.realpath(filename)
parents = path.split('/') //make an array of all the dirs in the path. 0 will be the original basefilename
newFilename=os.path.dirname(filename)+directory +parents[-1:][0] //reorganize data into format you want
os.rename(filename, newFilename)//rename the file
你应该和os.walk()一起去。它将根据给定的目录参数映射目录树,并生成文件名
使用os.walk()可以通过以下方式实现所需的结果:
相关问题 更多 >
编程相关推荐