第一个先成生,再运行另一个
##
q.pyimport os
path = "C:\Users\john\Desktop\data\sbaidu" #dir
dlist = os.walk(path)
outdict = {}
for d in dlist:
sdir = d[0]
for i in d[1:]:
for file in i:
p = sdir+"\\"+file
outdict[p] = 1
fd = open("qout.txt",'w') #write to file qout.txt
for key in outdict.keys():
fd.write(key+'\n')
fd.close()
这是另一个文件
import os
qfile = "qout.txt" #old file
mfile = "mout.txt" #the new file
data = {}
fd = open(qfile)
n = 1
for line in fd:
data[n] = line[:-1]
n += 1
fd.close()
fd = open(mfile)
n = 1
for line in fd:
file = line[:-1]
if file!=data[n]:
print data[n] ,"move to ",file
os.rename(data[n],file)
else:
pass
n += 1