【发布时间】:2020-09-15 10:47:54
【问题描述】:
一个简短的问题。我桌面上的 tester 文件夹中有多个文件。现在我想重写所有这些文件,在它们的文件名末尾添加“已移动”,并将它们移动到我桌面上一个名为 tester1 的新文件夹中。有人知道吗?先感谢您。这是我当前的代码:
source = r'c:\data\AS\Desktop\tester'
#Take the absolute filepaths from all the files in tester and open them.
for file in os.listdir(source):
file_paths = os.path.join(source, file)
with open(file_paths, 'r') as rf:
print(rf.read() + '\n')
【问题讨论】:
-
这能回答你的问题吗? How to move a file?
-
它不像我的那样具体:(
-
不要读取文件,然后将内容写入新文件,只需执行正常的文件复制/重命名操作:stackoverflow.com/questions/123198/…
-
您想重写文件还是只是将它们移动到一个修改了名称的新位置?
-
我想将它们移动到一个新的位置并修改了名称。