0

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. I am facing following problem: 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.

Alternate method or other pointers for the same would be a great help. Thanks in advance.

Community
  • 1
  • 1
Maverik
  • 23
  • 2

1 Answers1

0

What you could try to do is to hide the files you don't want to copy, then execute the xcopy, and then unhide the files again.

Look at my answer of question Windows batch script to delete everything in a folder except one. That question was related do deleting files (excluding some files), but you can probably use the same trick for xcopy-ing files.

Community
  • 1
  • 1
Patrick
  • 23,217
  • 12
  • 67
  • 130
  • -This is an alternate approach, but again, I won't be knowing the names of folders to be hidden. They are coming at runtime. – Maverik Aug 19 '11 at 11:02