17

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.

joerage
  • 4,863
  • 4
  • 38
  • 48

3 Answers3

23

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.

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • 3
    This goes to c:\windows\system32 not the current folder (at least on my Windows 7 PC). – under Mar 17 '17 at 00:31
4

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.stack.imgur.com/Xyxt4.png

Cosmin
  • 21,216
  • 5
  • 45
  • 60
DrSquirrel
  • 41
  • 1
2

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"
ptair
  • 177
  • 1
  • 11
  • This works great for local paths, but does not support UNC paths. - But at least it fails with a message stating exactly that - as opposed to the option without these lines, which just silently uses the Windows path. – I'm with Monica May 08 '19 at 08:16