x递归地复制目录和子目录并按扩展名仅过滤文件名

发布于 2024-09-03 18:17:16 字数 249 浏览 3 评论 0原文

这是我现在所拥有的:

xcopy "c:\projects\SampleProject" "c:\temp\copytest" /E /H /EXCLUDE:elist.txt

它可以完成我需要的所有工作,除了按扩展名过滤文件名之外。

例如:复制 c:\temp\copytest 及其子目录中的所有 *.exe 文件。

怎么做呢?

Here is what i have for now:

xcopy "c:\projects\SampleProject" "c:\temp\copytest" /E /H /EXCLUDE:elist.txt

It does all the job i need except filtering filenames by extensions.

For example: copy all *.exe files from c:\temp\copytest and subdirectories.

How to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

痕至 2024-09-10 18:17:16

我碰巧也需要这个,并发现如果您想将特定类型的文件复制到一个新文件夹,保持当前文件夹结构,您只需要这样做

xcopy [SourcePath]*.mp3 [DestinationPath]  /sy

/s: 复制目录和子目录,除非它们为空。如果
如果省略 /s,xcopy 将在单个目录中工作。

/y :禁止提示确认您要覆盖
现有目标文件

文档

I happened to need this too, and found out that if you want to xcopy files with specific type to a new folder keeping the current folder structure you need only to do this

xcopy [SourcePath]*.mp3 [DestinationPath]  /sy

/s: Copies directories and subdirectories, unless they are empty. If
you omit /s, xcopy works within a single directory.

/y : Suppresses prompting to confirm that you want to overwrite an
existing destination file

Documentation

等风也等你 2024-09-10 18:17:16

类似于:

@echo off
setlocal
set DIR=
set OUTPUTDIR=C:\Documents and Settings\<username>\Desktop\sandbox1\output
for /R %DIR% %%a in (*.mp3) do xcopy "%%a" "%OUTPUTDIR%"

请参阅 (http://technet.microsoft.com/en-us /library/bb490909.aspx)

Something like:

@echo off
setlocal
set DIR=
set OUTPUTDIR=C:\Documents and Settings\<username>\Desktop\sandbox1\output
for /R %DIR% %%a in (*.mp3) do xcopy "%%a" "%OUTPUTDIR%"

See (http://technet.microsoft.com/en-us/library/bb490909.aspx)

庆幸我还是我 2024-09-10 18:17:16

我需要相同的过程(使用排除过滤器复制文件夹)并使用@pollirrata 的示例。

我必须提到的一件事是,为了复制文件夹,我需要为目标目录指定反斜杠以禁止提示问题。

因此,我以以下语法结束:

xcopy SourceFolder DestinationFolder\ /EXCLUDE:exclude.txt

exclude.txt 文件的内容:

.mp3

要仅复制具有特定扩展名的文件(例如 *.exe),我使用了

xcopy SourceFolder\*.exe DestinationFolder\

I needed the same procedure (copy folders with exclude filter) and used the example of @pollirrata.

One thing I have to mention that in order to copy a folder I needed to specify a backslash for destination directory to suppress prompting a question.

So I ended with the following syntax:

xcopy SourceFolder DestinationFolder\ /EXCLUDE:exclude.txt

Contents of the exclude.txt file:

.mp3

To copy only files with specific extension (e.g. *.exe) I used

xcopy SourceFolder\*.exe DestinationFolder\
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文