recursive archival directory in windows (batch file/VBS)

Ramadhir Singh

Wasseypur
Adept
i have a root folder, containing sub-folder like:

Code:
\---Folder-01
    +---Random Directory Name 01
    |   |   9_1 - Klnp pf.xyz
    |   |   9_17 - Joy R5j.xyz
    |   |   9_30 - pre eye.xyz
    |   |
    |   \---SourceCode
    |       |   ppppy.txt
    |       |
    |       +---Changelog
    |       |       folder9.code
    |       |
    |       \---version
    |               41k.code
    |               3D.code
\---Folder-02
    +---Random Directory Name 02
    |   |   9_1_Klnp pf.xyz
    |   |   9_17 - Joy R5j.xyz
    |   |   9_30 - pre eye.xyz
    |   |
    |   \---Source - Code
    |       |   ppppy.txt
    |       |
    |       +---Changelog
    |       |       folder9.code
    |       |
    |       \---version, number
    |         |    41k.code
    |

I am trying to recursively archive "SourceCode" folder. which is labelled in in 4 variations , hence the (*code*) in below batch file
  1. Source Code
  2. Source-Code
  3. Source_Code
  4. SourceCode

The problem im facing is, the parent folder are not very organised and contains <spaces>, <_>, <-> etc
\Folder-01\Random Directory Name 01
as mention in above example.

Im trying to batch it, with the code below
Code:
for /d /r %%a IN (*code*) do (
  7z.exe a -r -tzip %%a.zip %%a\*
)

which is working fine in directories which doesnt contain any spaces, etc. and producing respective .zip files alongside *sourcecode* folder.

can someone help me how to tackle this delims issues?
Code:
/f  delims=*

is not helping :(

I have over 26,000 such sub-directory to archive hence looking to automate it.
-----------------

good to have, but not mandatory.
instead the the zip files named as sourcecode.zip, possible to adapt one stop above directory such as "Random Directory Name 01.zip" and post archival delete the original "sourcecode folder" keeping only these files

Code:
\---Folder-01
    +---Random Directory Name 01
    |   |   9_1 - Klnp pf.xyz
    |   |   9_17 - Joy R5j.xyz
    |   |   9_30 - pre eye.xyz
    |   |   SourceCode.zip

TIA.

please note, archive format is not necessary to be zip but its preferred as it can be opened in any OS without additional software. i can also use winrar instead of 7zip.
 
Last edited:
Usually if spaces are not getting matched you need to add quotes (single or double) around your patterns?
 
I meant put single or double quotes around the (*code*) part of your snippet? - inside the parentheses but around the stars? like this ("*code*") ?

I'm out of touch with this stuff so just a hunch.
 
I meant put single or double quotes around the (*code*) part of your snippet? - inside the parentheses but around the stars? like this ("*code*") ?

I'm out of touch with this stuff so just a hunch.
No, no.
The code-part is fine, as you see I put an asterisks around it.

The issue is the parent folder where the code folder is contained . That don’t have any patters and the is creating issues.
 
Back
Top