Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcopy with excluding folders (sub-directories)

I want to copy files and folders in a directory to another folder excluding sub-folders with files contains it, as for example I have a large number of files for node_modules directory which like 100Mb with 50K+ files, that I don't need to copy.

I tried using xcopy like this :

xcopy . c:\inetpub\CIVEBuildCentral\UI\. /Y /S /EXCLUDE:CIVE\UI\elist.txt

and elist.txt contains :

\node_modules\

But no luck, and its really annoying syntax and I don't see its optimal to check-in such a useless file for this case.

Any idea how to solve this?

like image 809
Al-Mothafar Avatar asked Jan 28 '16 11:01

Al-Mothafar


People also ask

Can xcopy exclude a directory?

You can let xcopy exclude folders or files in folder while copying from one directory to another with simple steps. Likewise, you have better choice to do exclusion during file backup or file syncing with a comprehensive tool.

How do I exclude in xcopy?

Using /excludeList each string in a separate line in each file. If any of the listed strings match any part of the absolute path of the file to be copied, that file is then excluded from the copying process. For example, if you specify the string "\Obj", you exclude all files underneath the Obj directory.

Can xcopy copy directories as well?

By default, the basic xcopy command only copies files in the directory you specify as the source directory. You must use the /E option to copy subdirectories in the source directory as well.


1 Answers

Well, after searching I found a similar question in StackOverflow but was not so helpful for my case:

  • Xcopy Command excluding files and folders ( its marked as duplicated but actually it's not really duplicated, it is the different case even if answer seemed the same way, and found no answer for my case anyway)

But I found that if you using Windows 7 or later, you can use robocopy instead, found its so powerful tool compared to old man xcopy, and no need to dirty work for exceptions, the command to achieve what I need replaced xcopy with :

robocopy . c:\inetpub\CIVEBuildCentral\UI\. /IS /S /XD node_modules

For full documentation for it, you can see this link: http://ss64.com/nt/robocopy.html

Solved my issue, and the output of the result was so nice, clear, and well formatted.

like image 62
Al-Mothafar Avatar answered Sep 21 '22 22:09

Al-Mothafar