0
我试图制作一个脚本,将除压缩文件以外的所有文件从源文件夹复制到另一个目标文件夹,并将源文件夹中的压缩文件解压缩到目的地,这是我到目前为止已经到达:将文件从一个文件夹复制到另一个文件夹
import os
import zipfile
import shutil
myPath = "Source dir"
for root, dirs, files in os.walk(myPath):
for file in files:
if file.endswith('.zip'):
fh = open(file, 'rb')
z = zipfile.ZipFile(fh)
for name in z.namelist():
outpath = "destination dir"#Put the name of the destination folder
z.extract(name, outpath)
fh.close()
else:
fileList = os.listdir('source dir')
for f in fileList:
shutil.copy2(f, 'destination directory')
该代码显示没有错误,但没有输出。
您建议的更改无效。您可以告诉我确切的错误。 – user3703286
用我给你的表达式,路径仍然是相对于'源路径'。你可以尝试'os.path.join(os.path.join('source dir',root),file),用真实的源代码路径代替'source dir'。 –