Because usually lazy, so the file mess. Sometimes when people want something. In order to add some of his own signature it is quite troublesome. On smoothly write a simple batch file prefix to modify a small demo.
code show as below:
# --** coding="UTF-8" **--
import os
def renameFileNames(filepath,prefix):
if not os.path.exists(filepath):
print("目录不存在!!")
filenames = os.listdir(filepath)
for data in filenames:
if (os.path.isfile(os.path.join(filepath,data))):
#增加前缀os.rename(os.path.join(filepath,data),os.path.join(filepath,prefix+data[3:]))
elif(os.path.isdir(os.path.join(filepath,data))):
renameFileNames(os.path.join(filepath,data))
if __name__ == "__main__":
filepath = "E:\\"
prefi = "前缀"
print("start")
if not os.path.exists(filepath,prefix):
print("目录不存在!!")
os._exit(1)
renameFileNames(filepath)