DOS 命令 - 使用 Robocopy 排除文件夹中的文件
我有一个包含许多其他子文件夹的文件夹。我正在尝试编写一个批处理文件,它将某些文件夹复制到硬盘上的另一个位置。我正在使用 xcopy 来实现此目的。文件夹结构如下所示:
FolderB1
FolderB2
FolderB22
File1.txt
File2.txt
File3.txt
我在FolderB1 中有一些.txt
文件,还有FolderB2 和FolderB22。我想复制FolderB2和FolderB22并跳过文件夹B1中包含的.txt
文件
我尝试使用/EXCLUDE
:xcopy
命令的参数,但它无法执行此操作。如果我将排除指定为 \FolderB1\*.txt
或类似的内容,则它不起作用。
主文件夹的数量未知。它可以是任何东西。此外,.txt
文件的名称没有固定模式。也检查过这个问题,但没有帮助。
另外,我想避免使用 del
命令,因为复制全部并再次删除会消耗时间。
这可以使用 Robocopy 来实现吗? 此处提出了完全相同的问题。 任何指针都会有用。提前致谢。
I have a folder containing many other sub-folders. I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using xcopy
for this. The folder structure is as shown below:
FolderB1
FolderB2
FolderB22
File1.txt
File2.txt
File3.txt
I have some .txt
files inside FolderB1, along with FolderB2 and FolderB22. I want to copy FolderB2 and FolderB22 and skip .txt
files contained in Folder B1
I tried using /EXCLUDE
: param of xcopy
command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt
or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of .txt
files. Have checked this question too, but did not help.
Also, I want to avoid using del
command, since copying all and deleting again would consume time.
Can this be achieved using Robocopy
? Exactly similar question is raised here.
Any pointers would be useful. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了澄清,我假设您的意思是排除
FolderB1
中的所有.txt
文件,但不排除位于其他位置的.txt
文件。您可以使用 robocopy 分两步完成此操作。首先复制除
.txt
之外的所有文件。在第二步中,仅复制.txt
文件,但排除FolderB1
。To clarify, I asume you mean to exclude all
.txt
files inFolderB1
, but not exclude.txt
located elsewhere.You can do that with robocopy in two steps. First copy all files except any
.txt
. And in the second step copy only.txt
files, but excludeFolderB1
.