Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 复印及;仅替换具有不同内容的文件_Powershell_Visual Studio 2012_Command Line_Merge - Fatal编程技术网

Powershell 复印及;仅替换具有不同内容的文件

Powershell 复印及;仅替换具有不同内容的文件,powershell,visual-studio-2012,command-line,merge,Powershell,Visual Studio 2012,Command Line,Merge,我将文件从文件夹A复制到文件夹B,包括子文件夹。如果文件夹B中已经存在文件,我只想在内容不同时替换它们。我不想覆盖具有相同内容的文件上的时间戳 我可以使用total commander或simmilar工具轻松地完成这项工作,但我希望只能使用命令行、visual studio命令提示符或powershell完成这项工作。tf diff命令是一个选项使用Robocopy。它可以从powershell或命令行调用 PS M:\> robocopy ----------------------

我将文件从文件夹A复制到文件夹B,包括子文件夹。如果文件夹B中已经存在文件,我只想在内容不同时替换它们。我不想覆盖具有相同内容的文件上的时间戳


我可以使用total commander或simmilar工具轻松地完成这项工作,但我希望只能使用命令行、visual studio命令提示符或powershell完成这项工作。tf diff命令是一个选项

使用Robocopy。它可以从powershell或命令行调用

PS M:\> robocopy

-------------------------------------------------------------------------------
  ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

    Started : Wed Apr 22 11:38:09 2015

    Simple Usage :: ROBOCOPY source destination /MIR

          source :: Source Directory (drive:\path or \\server\share\path).  
     destination :: Destination Dir  (drive:\path or \\server\share\path).  
            /MIR :: Mirror a complete directory tree.  

    For more usage information run ROBOCOPY /?

****  /MIR can DELETE files as well as copy them !

到目前为止你试过什么?如果这是我要解决的问题,那么我想我会使用文件哈希来决定是否复制。这给了我很好的比较:
tf folderdiff A B/recursive/filter:.xml
,但结果还包括一些文件夹,而不仅仅是文件。但是我不太擅长用管道和grepping命令行命令。你可以用robocy来做这类事情。打得好。/XC标志应将副本限制为已更改的文件。Robocopy根据时间戳比较文件。如果我在文件夹A和B中有相同的文件,但时间戳不同,robocopy会覆盖文件夹B中的文件,为了避免这种情况,我建议使用total commander(不管是什么),因为您使用一组非常主观的标准来确定哪个文件是当前文件。要使用任何方法自动执行此操作,都需要您有一种基于文件属性做出此决定的逻辑方法。我想将文件夹a复制到B,然后只将差异签入TFS。我无法覆盖所有文件,因为tfs会将它们识别为已更改,即使它们没有更改。我只是不想将成千上万个未经清理的文件签入tfs.robocy/?显示Robocopy的完整帮助。我想您正在寻找
Robocopy source destination/MIR/XO
,它将复制源代码,包括其中的结构和文件,但会跳过未更改的文件。请注意,它将删除从源中删除的目标文件。XO不会跳过未更改的文件