Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Windows batch: robocopy exclude files of specific subfolders

Hello experts,
I have A C:\Folder which contains multiple subfolders such as conf, lib, input, out, logs exports, etc.
I would like to launch robocopy command and exclude files of specific subfolders such as logs and out. The difficult part is that I need to exclude files of specific subfolders but keep the folder empty.
My attempt is.
 Robocopy C\Folder C:\Destionation /e /xf *.* 

Open in new window

The problem with this is that I exclude all files.
What I need is to exclude all files of specific folders and keep the folder involved empty.
If you have questions please contact me.
Thank you very much for your help.
Avatar of Vikas Bhat
Vikas Bhat

robocopy C:\Folder C:\Destination /MIR /E /NP /V /R:2 /W:10 /XD "Path of folder to exclude" /XF "path of files to exclude" 
you can add multiple path of folders and files
robocopy C:\Folder C:\Destination /MIR /E /NP /V /R:2 /W:10 /XD "Path of folder to exclude" /XF "path of files to exclude" /XD "Path1 of folder to exclude" /XF "path1 of files to exclude" 

Open in new window

Avatar of Luis Diaz

ASKER

I am aware of /mir option the problem is that I don't want to create subfolders of subfolders I want to keepfolders to exclude empty and do it with the minimum of commands
The other think that I was thinking is to use /xd and then mkdir of folders to keep empty.
If another expert have another approach please don't hesitate.
I don't understand the original question, perhaps an example?


»bp
Hello Bill,
I have C:\Package which contains the following folders
C:\Package\bin
C:\Package\conf
C:\Package\log
C:\Package\exports
I want to launch robocopy in order to copy all those subfoders to:
E:\Package
However I would like to exclude the content (files & folders) located at log and exports subfolders:
The aim is to have E:\Package with:
E:\Package\bin (with files and folders)
E:\Package\conf (with files and folders)
E:\Package\log (empty)
E:\Package\export (empty)

Let me know if it is clearer.
Below should be able to do what you want:

robocopy C:\Package E:\Package /MIR /E /NP /V /R:2 /W:10 /XD "C:\Package\log" /XD "C:\Package\exports" 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much Bill. For my knowledge. Could you please explain me  /np, /v, /r options.
This will help me to find the best way to manage issues with exclusions.
/R:n :: number of Retries on failed copies: default 1 million.
/W:n :: Wait time between retries: default is 30 seconds.


These specify the number of retries if a file can't be accessed or problems happen copying it.  I tend to keep it low for most scripts, but you will see numbers like 5 here when in production, to allow a few retries before moving along.  If you don't specify anything it defaults to a huge number and just keeps retrying forever.  The /W specifies the pause between each retry.

/V :: produce Verbose output, showing skipped files.

This just provides slightly more output to be logged during the copy, useful when testing, etc.

/NP :: No Progress - don't display percentage copied.

Skips the dynamic progress calculations and display during copies.  Can speed up the copy slightly and when running production mode, often as a scheduled job, you really don't need / want this.


»bp
Thank you Bill. Very clear.
I am looking your proposal and I was wondering if logs and exports folders have subfolders. First command will also copy them? I am asking this because in first command there is just /xf and not /XD.
Yes, all subfolders would also be created by the first ROBOCOPY command, is that what you want?


»bp
Yes, it is clear know. Thank you very much for your help.