你如何合并两个目录,或更换移动,从Windows命令行而不进行复制? [英] How do you merge two directories, or move with replace, from the windows command line without copying?

查看:169
本文介绍了你如何合并两个目录,或更换移动,从Windows命令行而不进行复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是我就写了一个快速python脚本来移动一些大的目录(全部在同一驱动器),错误地认为Windows命令行工具是不是一个完整的笑话和动根\\方向1根\\方向2 会像Windows资源管理器图形用户界面,合并的内容。我真的不在乎它是否取代或跳过重复的文件的文件夹内,因为没有任何。

So I just wrote a quick python script to move some large directories around (all on the same drive), incorrectly assuming windows command line tools weren't a complete joke and that move Root\Dir1 Root\Dir2 would, like windows explorer GUI, merge the contents. I really don't care whether it replaces or skips duplicate files within the folders because there aren't any.

不幸的是(在管理员命令提示符),

Unfortunately (in an admin command prompt),

C:\>mkdir a

C:\>mkdir b

C:\>mkdir b\a

C:\>move b\a .
Overwrite C:\a? (Yes/No/All): yes
Access is denied.

... :O

... ?? really ??!?

... no, actually really really ???

看来唯一的办法是复制和删除。痛苦可怜。

It seems the only way is to copy and delete. Painfully pathetic.

相关阅读:


  • <一个href=\"http://stackoverflow.com/questions/1118540/how-can-i-move-the-contents-of-one-directory-tree-into-another\">How我可以将一个目录树的内容到另一个?

如何合并分批CMD两个文件夹

<一个href=\"http://stackoverflow.com/questions/16502283/how-do-i-fix-access-denied-with-the-move-command-in-windows-7/16506856#comment34387855_16506856\">how我该修复:访问被拒绝与Windows移动命令7

我不写code。通过一个复制文件之一。的有什么办法来实现与没有抄袭?更换一个文件夹移动

I'm not writing code to copy files one by one. Is there any way to achieve a folder move with replace without copying?

我preFER使用一些本地的可执行文件,如果可能的。我也非常乐意使用Python,如果它支持它。

I'd prefer to use some native executable if possible. I'd also be quite happy to use python if it supported it.

推荐答案

布展所有文件,手动解决方法在Python。我还是从缫丝愚蠢

The move-all-files-manually workaround in python. I'm still reeling from the stupidity.

def moveTree(sourceRoot, destRoot):
    if not os.path.exists(destRoot):
        return False
    ok = True
    for path, dirs, files in os.walk(sourceRoot):
        relPath = os.path.relpath(path, sourceRoot)
        destPath = os.path.join(destRoot, relPath)
        if not os.path.exists(destPath):
            os.makedirs(destPath)
        for file in files:
            destFile = os.path.join(destPath, file)
            if os.path.isfile(destFile):
                print "Skipping existing file: " + os.path.join(relPath, file)
                ok = False
                continue
            srcFile = os.path.join(path, file)
            #print "rename", srcFile, destFile
            os.rename(srcFile, destFile)
    for path, dirs, files in os.walk(sourceRoot, False):
        if len(files) == 0 and len(dirs) == 0:
            os.rmdir(path)
    return ok

请张贴正确的答案,如果曾经有过一个!

Please post a proper answer if there ever is one!

这篇关于你如何合并两个目录,或更换移动,从Windows命令行而不进行复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆