挪动电影文件到相同名称的目录中

该代码实现了一个功能,检查当前工作目录下是否存在电影文件(如mp4, mkv, rmvb),然后将这些电影文件移动到以文件名创建的新目录中,便于NAS的刮削管理和组织。首先,它获取当前路径,然后遍历目录中的所有文件,判断是否为指定格式的电影文件。如果是,就创建同名目录,移动文件,并打印新目录的文件列表、文件大小及文件状态信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

挪动电影文件到相同名称的目录中,方便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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值