ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Xcopy Batch to run a loop inside of another loop loop


xcopy (var1)\(var2)\cache\*.* C:\backupdata\(var1)(+var2)
next to end

where var1 = list of names (20 or so)<Loop A>
var2 = list of their clients (up to 20)<LOOP B>

Tis is to create an exact copy of the files inside Only the cache folder stored in the backup above.  My problem is I always get lost in the "Loop-d-loop Logic" options.  (For x in ?= etc.) :-\ :-[
The folders exists in the past as stated each (name) may have from 0 to 20 (client) folders and each client folder has a (cache) folder.
I need to copy the complete contents of that folder to another one at C:\backupdata\"(name)+(client)"\cache\*.*
If the file already exists in that folder it should overwrite but none ever deleted.  After copying every subfolder and file in that "cache", it should shift to inputting the next client until it has run through all of them for that (name).  These names are all subfolder names in the root folder the batch starts in (or it can be one level down)
Root\names\clients\cache The structure is just like that.  Some (name)s may not have any (client)s but all (client)s have cache folders

The only reason for doing it this way is to avoid keeping backups of all the Other folders and files that are inside each client that are all standard.  I'm still trying to get inside the 2nd loop. :(  Any pointers.  I know it is probably something simple.  I tried pulling the variable from a list but it would be better if they could be pulled from the run itself since they are all names in a directory listing anyway.

The current process works fine but wastes a ton of time and space making redundant copies of unneeded files.


--- Code: Text ---REM start in the Root [email protected] offrem For each User folder do:for /d %%Y in (*) do (rem Change to User folder  pushd "%%~Y"rem For each Client folder do:  for /d %%U in (*) do (    robocopy "%%~U\cache" "C:\backupdata\%%~Y+%%~U\cache" /e    robocopy "%%~U\images\login" "C:\backupdata\%%~Y+%%~U\images\login" /e  )rem Return to parent folder (\Name)   popd)


[0] Message Index

Go to full version