By default, copying from the command prompt will prompt you to overwrite files that already exist in the target location.
默认情况下,从命令提示中复制会提示您覆盖目标位置中已经存在的文件。
You can add "/Y" to say "Yes to all" replacements.
您可以添加“/Y”来对所有的替换表示“Yes”。
But how can you say "No to all" ?
但是你怎么能对所有人说“不”呢?
In other words, I want to copy everything from one directory that does not already exist in the target.
换句话说,我希望复制目标中不存在的所有内容。
The closest thing I see is the XCOPY argument to only copy things after a specific mod-datetime.
我所看到的最接近的东西是XCOPY参数,它只在特定的mod-datetime之后复制东西。
13 个解决方案
#1
65
Unless there's a scenario where you'd not want to copy existing files in the source that have changed since the last copy, why not use XCOPY with /D without specifying a date?
除非有一个场景,您不想复制自上一个副本以来已经更改的源文件,为什么不使用XCOPY和/D而不指定日期呢?
#2
26
echo "No" | copy/-Y c:\source c:\Dest\
#3
21
You can make a text file with a single long line of "n" then run your command and put < nc.txt after it. I did this to copy over 145,000 instances where "No overwrite" was what I wanted and it worked fine this way.
你可以用一行“n”来创建一个文本文件,然后运行你的命令并设置< nc。三种。我这样做是为了复制超过145,000个实例,其中“没有覆盖”是我想要的,而且这样做很好。
Or you can just hold the n key down with something, but that takes longer than using the < to pipe it in.
或者你可以用一些东西按住n键,但这要比用< to pipe in。
#4
11
Here's a workaround. If you want to copy everything from A that does not already exist in B:
这里有一个解决方案。如果你想复制从A中不存在的所有东西B:
Copy A to a new directory C. Copy B to C, overwriting anything that overlaps with A. Copy C to B.
将A复制到一个新的目录C. Copy B到C,重写与A. Copy C到B的任何重叠部分。
#5
6
I use XCOPY
with the following parameters for copying .NET assemblies:
我使用XCOPY和以下参数来复制.NET程序集:
/D /Y /R /H
/D:m-d-y - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/Y - Suppresses prompting to confirm you want to overwrite an existing destination file.
/R - Overwrites read-only files.
/H - Copies hidden and system files also.
#6
6
I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so...
I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so…
xcopy {Source} {Destination} /E /D
Will copy without overwriting to pickup those files that are new or maybe failed before for some reason.
在没有覆盖的情况下复制,以拾取那些新的或者由于某种原因可能失败的文件。
Just try it, it works.
试试吧,它能行。
#7
5
I expect xxcopy has an option for that.
我希望xxcopy有一个选择。
Bingo:
宾果:
http://www.xxcopy.com/xxcopy27.htm#tag_231
http://www.xxcopy.com/xxcopy27.htm tag_231
2.3 By comparison with the file in destination
The switches in this group select files based on the
comparison between the files in the source and those in
the destination. They are often used for periodic backup
and directory synchronization purposes. These switches
were originally created as variations of directory backup.
They are also convenient for selecting files for deletion.
2.3.1 by Presence/Absence
The /BB and /U switches are the two switches which select
files by the pure presence or absence as the criteria.
Other switches in the this group (Group 2.3) are also
affected by the file in the destination, but for a
particular characteristics for comparison's sake.
/BB Selects files that are present in source but not in destination.
/U Selects files that are present in both source and destination.
-Adam
亚当
#8
4
this works fine
这工作好
no | cp -rf c:\source c:\Dest\
#9
3
echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)
echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)
#10
3
Try this:
试试这个:
robocopy "source" "destination" /e /b /copyall /xo /it
Copy that line into notepad and save as a .bat file. Run the file and it will copy everything from the source to the destination. When you run it again it will not replace files that are identical. when you change or a file changes it will replace the file at the destination.
将这一行复制到记事本中并保存为.bat文件。运行该文件,它将复制从源到目标的所有内容。当您再次运行它时,它将不会替换相同的文件。当您更改或更改文件时,它将替换目标中的文件。
test it out. I created a .txt file with a few works, ran the script, change the wording on the .txt file and ran the script again, it replace only the change file from the source.
对其进行测试。我创建了一个.txt文件,其中有一些工作,运行脚本,更改.txt文件中的文字,并再次运行脚本,它只替换来自源文件的更改文件。
/e=Copies subdirectories. Note that this option includes empty directories
/b=Copies files in Backup mode
/copyall=Copies all file information
/xo=Excludes older files. (this is what prevents it from copy the same file over and over)
/it=Includes "tweaked" files. (this will allow the copy and replace of modified files)
#11
3
Thanks for this. I am using the command line utility AzCopy (v 3.1.0.93) to move ~1 million files from my local PC to my Azure blob storage. I've got some duplicates and cannot babysit the copy to answer each prompt and don't want to re-upload the same file.
感谢。我正在使用命令行工具AzCopy (v3.1.0.93),将从本地PC到Azure blob存储的100万文件移动到我的Azure blob存储中。我有一些重复的文件,不能让复制的副本回答每个提示,也不想重新上传相同的文件。
The AzCopy utility offers a /Y command to suppress the confirmation prompts but ends up telling it to overwrite the destination file. Going this route I was able to get it to NOT re-upload the file. However, it does seem like a bit of a hack since it is not actually answering the prompt with "No", instead I get the error "No input is received when user needed to make a choice among several given options." but does not upload the file.
AzCopy实用程序提供了一个/Y命令来抑制确认提示,但最终告诉它覆盖目标文件。走这条路线,我可以让它不重新上传文件。然而,它看起来有点像黑客,因为它实际上并没有回答“不”的提示,相反,我得到了错误“当用户需要在几个给定选项中做出选择时,没有收到输入”,但是没有上传文件。
Here is the command I used: echo n | AzCopy /Source:"{file path}" /Dest:"{blob storage URL}" /DestKey:{key}
下面是我所使用的命令:echo n | AzCopy /Source:“{file path}”/ est:“{blob storage URL}”/DestKey:{key}
Hope this helps the next guy.
希望这能帮助下一个人。
#12
2
Depending on the size and number of files being copied, you could copy the destination directory over the source first with "yes to all", then do the original copy you were doing, also with "yes to all" set. That should give you the same results.
根据正在复制的文件的大小和数量,您可以将目标目录复制到源文件中,首先是“yes to all”,然后是您正在做的原始副本,也可以是“yes to all”集合,这将给您带来相同的结果。
#13
0
We used "robocopy" through "invoke-command" to copy a huge amount of VMs in our environment. We've discovered that "robocopy" unexpectedly exits sometimes and the whole proccess goes to down. So we've decided to use "xcopy". Now we're checking it's work and to "create" "Not for all" option we use that function (powershell):
我们通过“invoke-command”来使用“robocopy”来在我们的环境中复制大量的vm。我们发现“robocopy”有时会出人意料地退出,整个过程就会失败。所以我们决定使用“xcopy”。现在我们检查它的工作,并“创建”“不是所有的”选项,我们使用这个函数(powershell):
function gen_long_no([string]$path) { $result = ""; Get-ChildItem $path -Recurse | ? { if ($_.PSIsContainer -eq $false) { $result += "n" } }; return $result }
函数gen_long_no([string]$path) {$result = ";Get-ChildItem $path -递归| ?{ if($ _。PSIsContainer -eq $false) {$result += "n"};返回$结果}
Maybe helps somebody.
也许可以帮助别人。
#1
65
Unless there's a scenario where you'd not want to copy existing files in the source that have changed since the last copy, why not use XCOPY with /D without specifying a date?
除非有一个场景,您不想复制自上一个副本以来已经更改的源文件,为什么不使用XCOPY和/D而不指定日期呢?
#2
26
echo "No" | copy/-Y c:\source c:\Dest\
#3
21
You can make a text file with a single long line of "n" then run your command and put < nc.txt after it. I did this to copy over 145,000 instances where "No overwrite" was what I wanted and it worked fine this way.
你可以用一行“n”来创建一个文本文件,然后运行你的命令并设置< nc。三种。我这样做是为了复制超过145,000个实例,其中“没有覆盖”是我想要的,而且这样做很好。
Or you can just hold the n key down with something, but that takes longer than using the < to pipe it in.
或者你可以用一些东西按住n键,但这要比用< to pipe in。
#4
11
Here's a workaround. If you want to copy everything from A that does not already exist in B:
这里有一个解决方案。如果你想复制从A中不存在的所有东西B:
Copy A to a new directory C. Copy B to C, overwriting anything that overlaps with A. Copy C to B.
将A复制到一个新的目录C. Copy B到C,重写与A. Copy C到B的任何重叠部分。
#5
6
I use XCOPY
with the following parameters for copying .NET assemblies:
我使用XCOPY和以下参数来复制.NET程序集:
/D /Y /R /H
/D:m-d-y - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/Y - Suppresses prompting to confirm you want to overwrite an existing destination file.
/R - Overwrites read-only files.
/H - Copies hidden and system files also.
#6
6
I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so...
I know you all think /D: date is going to use date stuff, but just /D without the: does exactly what we want so…
xcopy {Source} {Destination} /E /D
Will copy without overwriting to pickup those files that are new or maybe failed before for some reason.
在没有覆盖的情况下复制,以拾取那些新的或者由于某种原因可能失败的文件。
Just try it, it works.
试试吧,它能行。
#7
5
I expect xxcopy has an option for that.
我希望xxcopy有一个选择。
Bingo:
宾果:
http://www.xxcopy.com/xxcopy27.htm#tag_231
http://www.xxcopy.com/xxcopy27.htm tag_231
2.3 By comparison with the file in destination
The switches in this group select files based on the
comparison between the files in the source and those in
the destination. They are often used for periodic backup
and directory synchronization purposes. These switches
were originally created as variations of directory backup.
They are also convenient for selecting files for deletion.
2.3.1 by Presence/Absence
The /BB and /U switches are the two switches which select
files by the pure presence or absence as the criteria.
Other switches in the this group (Group 2.3) are also
affected by the file in the destination, but for a
particular characteristics for comparison's sake.
/BB Selects files that are present in source but not in destination.
/U Selects files that are present in both source and destination.
-Adam
亚当
#8
4
this works fine
这工作好
no | cp -rf c:\source c:\Dest\
#9
3
echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)
echo N | copy /-y $(SolutionDir)SomeDir $(OutDir)
#10
3
Try this:
试试这个:
robocopy "source" "destination" /e /b /copyall /xo /it
Copy that line into notepad and save as a .bat file. Run the file and it will copy everything from the source to the destination. When you run it again it will not replace files that are identical. when you change or a file changes it will replace the file at the destination.
将这一行复制到记事本中并保存为.bat文件。运行该文件,它将复制从源到目标的所有内容。当您再次运行它时,它将不会替换相同的文件。当您更改或更改文件时,它将替换目标中的文件。
test it out. I created a .txt file with a few works, ran the script, change the wording on the .txt file and ran the script again, it replace only the change file from the source.
对其进行测试。我创建了一个.txt文件,其中有一些工作,运行脚本,更改.txt文件中的文字,并再次运行脚本,它只替换来自源文件的更改文件。
/e=Copies subdirectories. Note that this option includes empty directories
/b=Copies files in Backup mode
/copyall=Copies all file information
/xo=Excludes older files. (this is what prevents it from copy the same file over and over)
/it=Includes "tweaked" files. (this will allow the copy and replace of modified files)
#11
3
Thanks for this. I am using the command line utility AzCopy (v 3.1.0.93) to move ~1 million files from my local PC to my Azure blob storage. I've got some duplicates and cannot babysit the copy to answer each prompt and don't want to re-upload the same file.
感谢。我正在使用命令行工具AzCopy (v3.1.0.93),将从本地PC到Azure blob存储的100万文件移动到我的Azure blob存储中。我有一些重复的文件,不能让复制的副本回答每个提示,也不想重新上传相同的文件。
The AzCopy utility offers a /Y command to suppress the confirmation prompts but ends up telling it to overwrite the destination file. Going this route I was able to get it to NOT re-upload the file. However, it does seem like a bit of a hack since it is not actually answering the prompt with "No", instead I get the error "No input is received when user needed to make a choice among several given options." but does not upload the file.
AzCopy实用程序提供了一个/Y命令来抑制确认提示,但最终告诉它覆盖目标文件。走这条路线,我可以让它不重新上传文件。然而,它看起来有点像黑客,因为它实际上并没有回答“不”的提示,相反,我得到了错误“当用户需要在几个给定选项中做出选择时,没有收到输入”,但是没有上传文件。
Here is the command I used: echo n | AzCopy /Source:"{file path}" /Dest:"{blob storage URL}" /DestKey:{key}
下面是我所使用的命令:echo n | AzCopy /Source:“{file path}”/ est:“{blob storage URL}”/DestKey:{key}
Hope this helps the next guy.
希望这能帮助下一个人。
#12
2
Depending on the size and number of files being copied, you could copy the destination directory over the source first with "yes to all", then do the original copy you were doing, also with "yes to all" set. That should give you the same results.
根据正在复制的文件的大小和数量,您可以将目标目录复制到源文件中,首先是“yes to all”,然后是您正在做的原始副本,也可以是“yes to all”集合,这将给您带来相同的结果。
#13
0
We used "robocopy" through "invoke-command" to copy a huge amount of VMs in our environment. We've discovered that "robocopy" unexpectedly exits sometimes and the whole proccess goes to down. So we've decided to use "xcopy". Now we're checking it's work and to "create" "Not for all" option we use that function (powershell):
我们通过“invoke-command”来使用“robocopy”来在我们的环境中复制大量的vm。我们发现“robocopy”有时会出人意料地退出,整个过程就会失败。所以我们决定使用“xcopy”。现在我们检查它的工作,并“创建”“不是所有的”选项,我们使用这个函数(powershell):
function gen_long_no([string]$path) { $result = ""; Get-ChildItem $path -Recurse | ? { if ($_.PSIsContainer -eq $false) { $result += "n" } }; return $result }
函数gen_long_no([string]$path) {$result = ";Get-ChildItem $path -递归| ?{ if($ _。PSIsContainer -eq $false) {$result += "n"};返回$结果}
Maybe helps somebody.
也许可以帮助别人。