I have a directory that I want to copy to another directory using Robocopy.exe.
My plan is to exclude a few files from the root of the source directory. In fact, I'd like to ONLY exclude .html files from the ROOT of the directory.
The trick is that I'm currently using /E which is currently causing all subfolders to be processed too.
Therefore, the current outcome of my operation is that if I use:
/E /XF "*.html"
I'm going to exclude all HTML files site-wide.
Is there a way that I can keep copying all sub-folders, but also use XF to exclude .html files from the root?
Something like:
/E /XF "c:\releases\website_source\*.html"
The most important switches in this command are the /XD which allows you to exclude folders, and /XF that you can use to exclude files. The other options are optional, but you should use these options that you should use in any standard copy process using Robocopy.
I preface them with "rc" (for robocopy), then some recognizable notation for the application or part of the file system in the robocopy command, then append "B" or "R" (for Backup or Restore), then "I" or "X" (for Include or Exclude), then "D" or "F" (for Directory or File).
Robocopy normally overwrites those. :: With the Changed, Older, and Newer classes excluded, Robocopy will exclude files existing in the destination directory.
Robocopy allows you to filter items not just by file but by directory name too. Using robocopy /xd , you can exclude certain directories matching a specific name. When copying multiple folders, use the /XD switch to exclude folders from the run.
Ok, so for no real reason, I had to find a way to answer this.
I could only find a "decent" way using powershell and it is still messy.
So first, edit the following powershell to match your needs:
$files = Get-ChildItem c:\releases\website_source -Filter {*.html}
"/XF" > c:\temp\exclude.rcj
foreach ($f in $files) {$f.FullName >> c:\temp\exclude.rcj}
This creates a list of files after the /XF command in a robocopy "job" file.
Then call your robocopy command as normal but add /job:c:\temp\exclude.rcj
to the end of it. This will basically make a complex /XF for each root HTML file simpler to write in your script.
Note you can do the above with a batch file, but I'm better with powershell then batch for looping and such.
Yes I realize this is a somewhat dated question at this point, but I needed something to do.
My solution would be indecent but very easy to understand. I would just perform the task with a two line batch file. Robocopy the root folder (but not subdirectories) - including .html files. Then next line Robocopy including all subs (excluding *.html)
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