import os
directoryPath = '/Users/shirin/Desktop/Artez'
lstDir = os.walk(directoryPath)
for root, dirs, files in lstDir:
for fichero in files:
(filename, extension) = os.path.splitext(fichero)
if filename.find('untitle') != -1: # == 0 if starting with untitle
os.system('mv '+directoryPath+filename+extension+' '+directoryPath+'$(date +"%Y_%m_%d")'+filename+extension)
在这种情况下,^{} 函数可能更有用:
您的函数不会打印任何内容,因为名称中可能没有以
.*
结尾的文件。glob.glob()
函数将为您执行文件扩展。在然后,您可以使用此命令重命名文件,如下所示:
^{pr2}$Python
datetime
对象可用于获取合适的时间戳。在Python字符串比较器不支持通配符。您可以在文本中的任何位置搜索“untitled.”:
请记住,这将包括在文件的任何位置有“untitled.”的任何文件。在
试试这种方法
相关问题 更多 >
编程相关推荐