简体   繁体   English

我们可以使用 robocopy 来复制文件而不是文件夹吗

[英]Can we use robocopy to copy files instead of folders

I need to copy a particular file from one location to another., Is it possible to use robocopy to do same.我需要将特定文件从一个位置复制到另一个位置。是否可以使用 robocopy 来做同样的事情。

Whilst Robocopy can be persuaded to copy a single file it is much simpler to use copy or xcopy.虽然可以说服 Robocopy 复制单个文件,但使用 copy 或 xcopy 要简单得多。

I was trying to figure this problem out.我试图解决这个问题。 I finally found my own solution and maybe it will help.我终于找到了自己的解决方案,也许它会有所帮助。

I noticed that the syntax used to select the entire directory could be used to select a single file.我注意到用于 select 整个目录的语法可以用于 select 单个文件。

ROBOCOPY "*" "Directory source" "Directory Output unc path or non"

The above code will copy everything from the directory source folder to the directory output path.上面的代码会将目录源文件夹中的所有内容复制到目录 output 路径中。

Let's say you only wanted to copy 1 file from the directory source named "test.txt"假设您只想从名为“test.txt”的目录源中复制 1 个文件

In order to do that use the following code:为此,请使用以下代码:

ROBOCOPY "*test.txt" "Directory source" "Directory Output unc path or non"

Thats about it.就是这样。 It works really well and will only copy the file name you want.它工作得非常好,只会复制你想要的文件名。

Alternatively you can use或者,您可以使用

ROBOCOPY "*.txt" "Directory source" "Directory Output unc path or non"

to copy out all text documents from the directory source.从目录源复制所有文本文档。 Similarly this will also work with any.ext同样,这也适用于 any.ext

.zip.exe.txt.pdf etc.. .zip.exe.txt.pdf等。

I signed up to answer this question with a better method.我注册用更好的方法来回答这个问题。 Let me know if I succeeded.让我知道我是否成功了。

Yes, either wrap it in an an exec or use the Robocopy that is wrapped as part of the msbuild extension pack see: http://www.msbuildextensionpack.com/help/4.0.3.0/index.html是的,要么将其包装在一个 exec 中,要么使用作为 msbuild 扩展包的一部分包装的 Robocopy,请参阅: http://www.msbuildextensionpack.com/index.ZFC335EZ88888

You want to use the MSBuild.ExtensionPack.FileSystem.RoboCopy task.您想使用 MSBuild.ExtensionPack.FileSystem.RoboCopy 任务。 Makes copying much quicker.使复印速度更快。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM