casio1374633

导航

 
import os
import sys

rootdir = os.getcwd()

for (dirpath, dirnames, filenames) in os.walk(rootdir):
for filename in filenames:
testfile = os.path.join(dirpath, filename)
if (os.path.isfile(testfile) == True):
print(os.path.join(dirpath, filename))
#------------------------------
match_num = filename.find('-')
if (match_num == -1):
match_num = filename.find('.')

if (match_num != -1):
if (filename[:match_num].isdigit() == True):
newname = filename[match_num+1:]
os.rename(os.path.join(dirpath, filename), dirpath + os.sep + newname)
else:
print("不是000x开头")
else:
print("匹配失败")


#===========================================
print(">> NEW")
for (dirpath, dirnames, filenames) in os.walk(rootdir):
for filename in filenames:
testfile = os.path.join(dirpath, filename)
if (os.path.isfile(testfile) == True):
print(os.path.join(dirpath, filename))
posted on 2016-12-05 16:04  casio1374633  阅读(352)  评论(0编辑  收藏  举报