joerage
joerage

Reputation: 4923

Robocopy copy contents of current folder

How would you translate this xcopy command into Robocopy:

xcopy *.* "C:\DestinationFolder\"

Keeping in mind that the current folder where the command is run changes dynamically (and hence the source folder is unknown in advance).

Thanks.

Upvotes: 18

Views: 40320

Answers (3)

ptair
ptair

Reputation: 187

As an addition: If robocopy is started from an administrator console, the current folder "." will point to Windows\system32.

You can use the following commands at the top of your batch file to fix this:

@setlocal enableextensions  
@cd /d "%~dp0"

Upvotes: 2

Martin Beckett
Martin Beckett

Reputation: 96109

robocopy . "c:\dest"

Note you don't need to specify a wildcard in robocopy, by default it copies everything unless you use the /xf /xd flags to exclude certain files.

Upvotes: 24

DrSquirrel
DrSquirrel

Reputation: 41

Robocopy DOES support wildcards.

You're expecting > robocopy SOURCE DEST but type > robocopy *.txt c:\folderdest\ to copy the current folder. If you look at the output from robocopy it will show "Files : *.txt" and "Source = c:\folderdest"

So in fact you can do > robocopy WILDCARD SOURCE DEST. If you want to use the CURRENT folder you need to use . (as has been mentioned here). So you would use > robocopy *.txt . c:\folderdest\.

Screenshot: https://i.sstatic.net/Xyxt4.png

Upvotes: 4

Related Questions