DOS Commands- Excluding files in a folder in xcopy

一个人想着一个人 提交于 2019-12-25 02:38:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7117376/dos-commands-excluding-files-in-a-folder-in-xcopy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!