recursive archival directory in windows (batch file/VBS)

Discussion in 'Programming' started by netant, Sep 28, 2018.

  1. netant

    netant Well-Known Member

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

    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
    for /d /r %%a IN (*code*) do (
      7z.exe a -r -tzip %%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?
    /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, possible to adapt one stop above directory such as "Random Directory Name" and post archival delete the original "sourcecode folder" keeping only these files

        +---Random Directory Name 01
        |   |   9_1 - Klnp
        |   |   9_17 - Joy
        |   |   9_30 - pre
        |   |

    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.
    #1 netant, Sep 28, 2018
    Last edited: Sep 28, 2018
  2. vishalrao

    vishalrao Global Moral Police

    Usually if spaces are not getting matched you need to add quotes (single or double) around your patterns?
  3. OP

    netant Well-Known Member

    there isn't any patters on the directory .. that the issue.
  4. vishalrao

    vishalrao Global Moral Police

    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.
  5. OP

    netant Well-Known Member

    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.

Share This Page