开发者

xcopy directories and subdirectories recursively and filter only filenames by extension

开发者 https://www.devze.com 2023-01-02 01:57 出处:网络
Her开发者_JAVA百科e is what i have for now: xcopy \"c:\\projects\\SampleProject\" \"c:\\temp\\copytest\" /E /H /EXCLUDE:elist.txt

Her开发者_JAVA百科e 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?


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


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)


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\
0

精彩评论

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

关注公众号