I am trying to use the /if (Include Files) flag for robocopy to provide an array list of all the files I would like to copy.
I successfully did this when setting the source directory just 1 level up (e.g. C:\Documents\Folder), and providing just the filename in the array after /if (e.g /if file1).
However, when I try to set the source directory 2 levels up (e.g. C:\Documents) and pass the entire filepath into /if (e.g if/ C:\Documents\Folder\file1 [no extension on these files]), the robocopy will not recognise the entire filepath as a valid parameter. I tried with just one filepath instead of an array, and multiple ways of inputting this such as with double quotes around the filepath, but still errored with invalid parameter.
To test, I tried to do the opposite with /xf, and the robocopy then excluded this file successfully.
Is this a limitation of the /if flag for robocopy?
robocopy C:\Documents D:\Documents /e /tee etc... /if "C:\Documents\Folder\file1"
Thanks.
The /if option is for creating robocopy jobs. It supports only filters, not paths. So you could do:
robocopy C:\Documents D:\Documents /e /if *.pdf /save:myjob
The robocopy syntax allows specifying file names to copy, but not paths:
robocopy C:\Documents\Folder D:\Documents\Folder file1 file2
(Note: The filenames specified here and with the /if option are combined.)
If your files all reside in the same folder, you can just specify all their names. If they are in different folders, you have to run the command for each folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With