I am trying to copy a folder from one place to a network place. But I want to exclude some folder from being copied.
:: time and date stamp YYYYMMDD, HHMMSS and YYYY-MM-DD_HH-MM-SS
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set stamp=%YYYY%-%MM%-%DD%T%HH%-%Min%-%Sec%
mkdir "\\serv1\b$\Script Backup\%stamp%"
XCOPY C:\source "\\serv1\b$\Script Backup\%stamp%" /S
this xcopy command will copy the entire C:\source over to the network location. but I want to exclude the following directores that are currently inside C:\source
I want to exclude the following folders
C:\source\dba
C:\source\staging
C:\source\testing
How can I do that?
As per Product Documentation - Xcopy:
/exclude:filename1[+[filename2]][+[filename3]] : Specifies a list of files containing strings.
and (emphasis added):
List each string in a separate line in each file. If any of the listed strings match any part of the absolute path of the file to be copied, that file is then excluded from the copying process. For example, if you specify the string "\Obj\", you exclude all files underneath the Obj directory. If you specify the string ".obj", you exclude all files with the .obj extension.
Thus, create a file (for example exclude.txt) to contain:
C:\source\dba
C:\source\staging
C:\source\testing
and instruct /exclude: parameter to refer to it:
XCOPY C:\source "\\serv1\b$\Script Backup\%stamp%" /S /exclude:exclude.txt