2

I have a folder containing many other sub-folders. I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using xcopy for this. The folder structure is as shown below:

FolderB1
  FolderB2
  FolderB22
  File1.txt
  File2.txt
  File3.txt

I have some .txt files inside FolderB1, along with FolderB2 and FolderB22. I want to copy FolderB2 and FolderB22 and skip .txt files contained in Folder B1

I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.

The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of .txt files. Have checked this question too, but did not help.

Also, I want to avoid using del command, since copying all and deleting again would consume time.

Can this be achieved using Robocopy? Exactly similar question is raised here. Any pointers would be useful. Thanks in advance.

Community
  • 1
  • 1
Pramod Karandikar
  • 5,289
  • 7
  • 43
  • 68

1 Answers1

3

To clarify, I asume you mean to exclude all .txt files in FolderB1, but not exclude .txt located elsewhere.

You can do that with robocopy in two steps. First copy all files except any .txt. And in the second step copy only .txt files, but exclude FolderB1.

robocopy c:\source c:\destination /s /xf *.txt
robocopy c:\source c:\destination *.txt /s /xd c:\source\FolderB1
wimh
  • 15,072
  • 6
  • 47
  • 98