Python:通过迭代2个列表来复制文件

时间:2015-11-19 23:33:31

标签: python arrays file io

我创建了两个数组,并让python获取用户输入来填充这些数组,如下所示:

#Establish the number directory paths
print "How many additional directories will you need to copy?"
dirCount = int(raw_input(prompt))
srcDirList = []
dstDirList = []

我想迭代它们并将srcDirList中的数据复制到dstDirList中的相应值。我已经这样设置了:

#iterate through both source and destination arrays and
#copy the additionally specified source directories to destination directories
for src, dst in zip(srcDirList, dstDirList):
    dir_copy(src, dst)

但是,我的脚本似乎只是卡在这里。它不会像它应该的那样复制,也不会退出或抛出错误。我有某种无限循环吗?这只是实现这个的可怕方式吗?

编辑:这是dir_copy的代码:

#copy function
def dir_copy(srcpath, dstdir):
    #set destination dirname to share basename with the source directory
    dirname = os.path.basename(srcpath)
    #set the actual directory path
    dstpath = os.path.join(dstdir, dirname)
    shutil.copytree(srcpath, dstpath)

0 个答案:

没有答案