1

I have a source folder where i have xml files and non xml files. I need to copy only non xml files from source to destination folder. I have written commands as below which does xml files copy from source to destination folder. But i need to non xml files. Kindly help.

@echo on
set SRCROOT=D:\input
set DESTNAME=D:\archive

echo Creating Directories...
if not exist %DESTNAME% md %DESTNAME%

echo Copying Files...
copy /Y %SRCROOT%\*.xml %DESTNAME%

Update: I tried as below and it worked. Looping through the directory and copying all non xml files:

@echo on
set SRCROOT=D:\input
set DESTNAME=D:\archive

echo Creating Directories...
if not exist %DESTNAME% md %DESTNAME%

@echo off
for %%i in (%SRCROOT%\*.*) do if not "%%~xi" == ".xml" copy /Y %%i %DESTNAME%
Sathish D
  • 4,854
  • 31
  • 44
Anita
  • 185
  • 1
  • 6
  • 24

2 Answers2

1

Use robocopy instead. It is available with the OS since Windows7. The /xf option allows you to exclude files, like *.xml:

robocopy %SRCROOT% %DESTNAME% * /xf *.xml

Otherwise xcopy has the /exclude option, but it takes a file. See /exclude in xcopy just for a file type.

Community
  • 1
  • 1
Remus Rusanu
  • 288,378
  • 40
  • 442
  • 569
1

xcopy has an exclude option:

echo .xml >>c:\temp\exclude.txt
xcopy %SRCROOT%\*.* %DESTNAME% /exclude:c:\temp\exclude.txt
del c:\temp\exclude.txt
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103