且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在python中将文本文件中列出的文件从一个文件夹移动到另一个文件夹

更新时间:2022-12-30 11:25:15

我会尝试:

import os

dst = "C:\\Users\\Aydan\\Desktop\\1855\\" # make sure this is a path name and not a filename

with open('1855.txt') as my_file:
    for filename in my_file:
        src = os.path.join("C:\\Users\\Aydan\\Desktop\\data01\\BL\\ER\\D11\\fmp000005578\\", filename.strip() ) # .strip() to avoid un-wanted white spaces
        os.rename(src, os.path.join(dst, filename.strip()))