我正在尝试创建一个shell脚本,将文件从一台计算机(员工的旧计算机)复制到另一台(员工的新计算机)。多亏了这里可爱的人,我已经可以复制文件了,但是我遇到了一个问题-如果我从一个有两个文件的目录出发:
C:\Users\specificuser\Documents\Test文件夹
…到这个目录。。。
C: \Users\specific用户\桌面
…我看到文件显示在桌面上,但这些文件所在的文件夹(测试文件夹)没有创建。在
以下是我使用的复制功能:#copy function
def dir_copy(srcpath, dstpath):
#if the destination path doesn't exist, create it
if not os.path.exists(dstpath):
os.makedir(dstpath)
#tag each file to the source path to create the file path
for file in os.listdir(srcpath):
srcfile = os.path.join(srcpath, file)
dstfile = os.path.join(dstpath, file)
#if the source file path is a directory, copy the directory
if os.path.isdir(srcfile):
dir_copy(srcfile, dstfile)
else: #if the source file path is just a file, copy the file
shutil.copyfile(srcfile, dstfile)
我知道我需要在目的地创建目录,只是不太确定怎么做。在
编辑:我发现我有一个类型(os.makedir操作系统而不是操作系统.mkdir). 我测试了它,它创建了它应该创建的目录。不过,我希望它创建一个新的目录,从它开始的地方。例如,在测试文件夹中有子测试文件夹。它已创建子测试文件夹,但不会创建测试文件夹,因为测试文件夹不是dstpath的一部分。有道理吗?在