我有两个目录:它们path/to/folder
里面path/to/otherfolder
都有几个子目录:path/to/folder/TEST1
, path/to/folder/TEST2
, path/to/otherfolder/TEST1
,path/to/otherfolder/TEST2
等。
我正在使用根文件夹中的所有子目录folder_path = glob.glob('path/to/folder/*')
然后我遍历每个子目录以获取其中的所有文件:
for folder in folder_path:
file_path = glob.glob(folder + '\*')
for files in file_path:
new_path = files.replace('folder', 'otherfolder')
with open(files, r) as f:
with open(new_path, 'wb') as wf:
do stuff
这不起作用,因为没有文件被写入。我想过简单地改变这条线,files.replace('\\folder\\', '\\otherfolder\\')
但我认为这不会奏效。
re
如果有人有任何想法,我想使用 Python 的库吗?