import os def getAllFiles(file_dir): L=[] for root, dirs, files in os.walk(file_dir): for file in files: if os.path.splitext(file)[1] == '.xlsx': L.append(os.path.join(root, file)) return L files=sorted(getAllFiles("/Volumes/下载/超级飞侠/超级飞侠第二季/测试")) print(files) sequence=0; for i, file in enumerate(files): filepath=os.path.dirname(file); filename=os.path.basename(file).split('.')[0] if len(filename)<=0: continue sequence=sequence+1 index="%03d" %(sequence) print("---"+filepath+"/"+filename) cmd="mv "+file+ " "+ filepath+"/"+index +"-"+ filename+".xlsx" print(cmd) os.system(cmd)