-1

I have folders structure like this.

C:\MyFolder\http+++one\
C:\MyFolder\http+++two\
C:\MyFolder\http+++three\
C:\MyFolder\Other+++One\
C:\MyFolder\Other+++Two\
C:\MyFolder\Other+++Three\

Need to copy only folders starting with Other+++ and DO NOT copy folders starting with http+++.

Now problem is number of folders with other and http+++ and other+++ prefix is dynamic it grows more every day so i can't exclude them by specifying each folder manually, have to use wildcard.

Need a working solution similar to this:

robocopy "C:\MyFolder" "D:\MyFolder" /MIR /XJ /NDL /NP /TEE /S /XD "C:\MyFolder\http*"

Obviously above command does not work.

3 Answers3

2

As robocopy searches for wildcards anywhere in the path string, a simple syntax to exclude these folders is:

/XD http*
harrymc
  • 498,455
1

Given that you are using robocopy, a Windows-only utility, I'm assuming you can run a batch script.
The following script will do what you are looking for, and it does not need to be run from any of the folders in question, in case you cannot write to them.

@echo off
setlocal enableextensions enabledelayedexpansion
for /f "delims=" %%A in ('dir /a:d /b "C:/MyFolder"') do ( 
    set folder=%%A
    set firstFourChars=!folder:~0,4!
    if NOT "!firstFourChars!" == "http" (robocopy "C:/MyFolder/%%A" "D:/MyFolder/%%A" /MIR /XJ /NDL /NP /TEE /S)
)

Explanation:

@echo off declutters the output, stopping the interpreter from saying every command it runs.
setlocal enableextensions enabledelayedexpansion makes the for loop work, by making the instructions contained within (...) to be executed one by one, and allowing access to current state of variables with !var! syntax.
for /f "delims=" %%A in ('dir /a:d /b "C:/MyFolder"') do (...) loops over all folders in C:/MyFolder. "delims=" is necessary to support folder name with spaces.
set folder=%%A sets the name of each folder to the variable called folder.
set firstFourChars=!folder:~0,4! sets the first four characters of every folder's name to the variable named firstFourChars.
if NOT "!firstFourChars!" == "http" (robocopy "C:/MyFolder/%%A" "D:/MyFolder/%%A" /MIR /XJ /NDL /NP /TEE /S) runs your robocopy command only if said first four characters do not match the literal http.

0

Appears to be duplicate of Robocopy exclude directories with wildcard but I can't close. You want to have a look at the duplicate anyway, specially this answer: https://superuser.com/a/1671577/705502