Just wondering the best way to do this in a single batch file. I have a folder called C:\Program\Foo and I want to grab all the folders except for the testing folder inside of foo, and I want to xcopy into D:\ so in D:\ foo will be there but no test folder.
开发者_JAVA技巧Is there a way I can loop through each folder and check for a certain name not to include?
using /Exclude would mean I would need an extra text file with "Testing" in it
I don't see why you could not create a temporary exclusion file (using a temporary folder, that is):
@ECHO OFF
FOR %%F IN ("%TEMP%\exclude.txt") DO SET tmpf=%%~sF
ECHO Testing>%tmpf%\exclude.txt
XCOPY source destination /EXCLUDE:%tmpf%\exclude.txt other options
Note: XCOPY
does not recognise double quotes as path delimiters in the /EXCLUDE
option and offers no alternative for specifying paths with spaces, which can be a problem on Windows XP systems. This limitation can be worked around by replacing the original path with its counterpart consisting only of short names. That is what the FOR
loop in the above script does for the %TEMP%
folder.
Can you use ROBOCOPY
?
ROBOCOPY C:\Program\Foo D:\ * /E /XD Test
/E
copies subfolders and files/XD
excludes directories
Use the EXCLUDE option and put your exclusions in that file. That will let you exclude entire directories.
http://www.pcreview.co.uk/forums/using-xcopy-backup-can-exclude-some-directories-t489674.html
xcopy "c:\document and settings" "i:\documents and settings\" /s /d /EXCLUDE:c:\a.txt
a.txt contains
\temp\ \temporary internet files\
You may need to use shorter DOS file names.
精彩评论