sam
sam

Reputation: 4684

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.

Upvotes: 0

Views: 2712

Answers (3)

3rrorLogic
3rrorLogic

Reputation: 21

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.

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.

Let's say you only wanted to copy 1 file from the directory source named "test.txt"

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

.zip .exe .txt .pdf etc..

I signed up to answer this question with a better method. Let me know if I succeeded.

Upvotes: 0

James Woolfenden
James Woolfenden

Reputation: 6671

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

You want to use the MSBuild.ExtensionPack.FileSystem.RoboCopy task. Makes copying much quicker.

Upvotes: 0

David Heffernan
David Heffernan

Reputation: 613352

Whilst Robocopy can be persuaded to copy a single file it is much simpler to use copy or xcopy.

Upvotes: 1

Related Questions