# -*- coding:utf-8 -*-
import os
import sys
import os.path
import shutil
arr = []
sourcefile = sys.argv[1]
fileList = os.listdir(sourcefile)
for file in fileList:
fileIndex = file.find('.')
if fileIndex == -1:
return '没有找到正确的切分点'
newFile = file[0:fileIndex]
arr.append(newFile)
data = list(set(arr))
print(data)
for file in fileList:
try:
fileIndex = file.find('.')
newFile = file[0:fileIndex]
for i in range(len(data)):
if newFile == data[i]:
newfilepath = sourcefile + newFile + '/'
if os.path.exists(newfilepath):
oldfile = sourcefile + file
newfile = newfilepath
shutil.move(oldfile,newfile)
else:
os.mkdir(newfilepath)
oldfile = sourcefile + file
newfile = newfilepath
shutil.move(oldfile,newfile)
else:
pass
except Exception,err:
print(err)
python脚本将目录下相同前缀的文件放到对应目录
最新推荐文章于 2025-05-17 17:07:22 发布