挪动电影文件到相同名称的目录中,方便NAS刮削管理
import os
import shutil
filepath = os.getcwd()
print('currentPath : ' + filepath)
moiveFormat = ['mp4', 'mkv', 'rmvb']
def isThisMoiveFile(fileName):
for moiveSuffixName in moiveFormat:
if (fileName.endswith(moiveSuffixName)):
return True
return False
if __name__ == "__main__":
if not os.path.exists(filepath):
print("目录不存在!!")
os._exit(1)
filenames = os.listdir(filepath)
for fileName in filenames:
if (os.path.isfile(fileName)):
print("=======")
#print(fileName)
if (isThisMoiveFile(fileName)):
directoryName = os.path.splitext(fileName)[0]
oldFilePath = os.path.join(filepath, fileName)
newFilePath = os.path.join(filepath, directoryName, fileName)
newDirectoryPath = os.path.join(filepath, directoryName)
if not os.path.exists(newDirectoryPath):
os.mkdir(directoryName)
#print('oldFilePath : ' + oldFilePath)
#print('newFilePath : ' + newFilePath)
#print('newDirectoryPath : ' + newDirectoryPath)
shutil.move(oldFilePath, newFilePath)
print(os.listdir(newDirectoryPath))
print('file size : '+ str(os.path.getsize(newFilePath)))
print(os.stat(newDirectoryPath))