开发者

Using Robocopy to exclude a file extension from the root directory

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 R开发者_开发知识库OOT 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"


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜