【问题标题】:Python, copy only directoriesPython,仅复制目录
【发布时间】:2016-10-25 07:12:24
【问题描述】:

我有一个包含一些文件列表的程序。我只需将列表中的目录和子目录复制到指定目录,不需要复制文件。我试过了,但它不起作用。

def copiarDirs():
items = list.curselection()              
desti = tkFileDialog.askdirectory()
for dirs in os.walk(items, topdown=False):
    for name in dirs: 
    #for i in items :                       
        aux=root+"/"+list.get(i)            
        tryhard=("cp "+str(aux)+" "+str(desti))
        os.system(tryhard)

【问题讨论】:

    标签: python directory copy subdirectory


    【解决方案1】:

    试试这个:

    import os
    
    def copyDirs(source, destination):
        for subdir, dirs, files in os.walk(source):
            for f in files:
                dir = destination + os.path.join(subdir).split(':')[1]
                if not os.path.exists(dir):
                    os.makedirs(dir)
    
    sourceDir = 'D:\\Work\\'
    destDir = 'D:\\Dest\\'
    copyDirs(sourceDir, destDir) #calling function
    

    【讨论】:

    • 很抱歉,它不起作用。另外我只需要复制curselection目录
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-10
    • 2014-09-22
    • 2011-10-14
    • 2016-06-27
    • 2018-07-24
    • 2013-11-16
    • 1970-01-01
    相关资源
    最近更新 更多