Windows Batch to Copy Files in an Excluded Set

GurcanK
GurcanK used Ask the Experts™
on
Dear Experts,

I would like to write a batch script (CMD) to copy files from c:\temp of one Windows machine to a shared folder let's say pshared in another machine. However, the script should copy files with names not starting with B,DE and F. How can I achieve this?

Best Regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
robocopy should do the trick (part of the OS since Vista/W2k8):
robocopy.exe "C:\Temp" "\\SomeServer\SomeShare" *.* /xf b* d* e* f* /r:0

Open in new window

Author

Commented:
Anything other than robocopy such as copy or xcopy?
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Not without additional scripting; and robocopy is far better anyway. In Vista, the xcopy help even provided a warning that it's deprecated and robocopy should be used instead.
not sure that pure batch can handle this other than copy all, then delete B*,D*,E*,F*.  
this works but is not very efficient
set typ=*.frm
set src=c:\ee
set dest=c:\ee\done
xcopy /C %Src%\%typ% %dest%
del /q %dest%\B*.*
del /q %dest%\E*.*
del /q %dest%\F*.*
del /q %dest%\G*.*

Open in new window


 
is vbscript ok ??
set typ=*.*
set src=c:\temp
set dest=\\zeus\phared
xcopy /C %Src%\%typ% %dest%
del /q %dest%\B*.*
del /q %dest%\E*.*
del /q %dest%\F*.*
del /q %dest%\G*.*

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial