我需要合并两个文件夹,
文件夹名为 12345 和 12345_
我如何合并两者?
我已经尝试过了,但最后得到的是“12345”。
for file in files:
subFolder = os.path.join(destpath, file[:6])
if not os.path.isdir(subFolder):
os.makedirs(subFolder)
shutil.copy(os.path.join(root, file), subFolder)
最佳答案
您可以使用类似这样的方法,它将所有文件从文件夹一复制到文件夹二,这样文件夹二将包含文件夹一和文件夹二的所有文件:
#!/usr/bin/env python
import subprocess as sbp
import os
path=raw_input('Please enter a path\n')
fol = os.listdir(path)
p2 = raw_input('Please enter a path\n')
for i in fol:
p1 = os.path.join(path,i)
p3 = 'cp -r ' + p1 +' ' + p2+'/.'
sbp.Popen(p3,shell=True)
关于python - 在python中合并两个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49122623/