使用 Robocopy 从根目录中排除文件扩展名
我想使用 Robocopy.exe 将一个目录复制到另一个目录。
我的计划是从源目录的根目录中排除一些文件。事实上,我只想从目录的根目录中排除 .html 文件。
诀窍是我当前正在使用 /E,它目前也会导致所有子文件夹被处理。
因此,我的操作的当前结果是,如果我使用:
/E /XF "*.html"
我将排除站点范围内的所有 HTML 文件。
有没有一种方法可以让我继续复制所有子文件夹,同时也使用 XF 从根目录中排除 .html 文件?
像这样的东西:
/E /XF "c:\releases\website_source\*.html"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,所以没有真正的原因,我必须找到一种方法来回答这个问题。
我只能找到一种使用 powershell 的“体面”方式,但它仍然很混乱。
因此,首先,编辑以下 powershell 以满足您的需求:
这将在 robocopy“作业”文件中的 /XF 命令之后创建文件列表。
然后照常调用 robocopy 命令,但将
/job:c:\temp\exclude.rcj
添加到其末尾。这基本上将使每个根 HTML 文件的复杂 /XF 更容易在脚本中编写。请注意,您可以使用批处理文件执行上述操作,但我最好使用 powershell,然后使用批处理循环等。
是的,我意识到这是一个有点过时的问题,但我需要做点什么。
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:
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.
我的解决方案可能不雅但很容易理解。
我只需使用两行批处理文件来执行该任务。
Robocopy 根文件夹(但不包括子目录) - 包括 .html 文件。
然后下一行 Robocopy 包括所有子文件(不包括 *.html)
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)