1

I'm struggling to achieve the following

    DIR1
    FileA
    FileB
    SUBDIR2
    --->FileC
    --->FileD
    --->SUBDIR3
    ------>FileE
    ------>FileF

    etc

and end up with :

    DIR1
    DIR1.7z
    SUBDIR2
    --->SUBDIR2.7z
    --->SUBDIR3
    ------>SUBDIR3.7z

    and at each level there would be multiple subdirectories and files

I have a working batch file that will recursively 7zip each file in to a separate archive but for another purpose (hiding sub directory names automatically) I am trying to work out how to at each subdirecty level put the files in to an archive for each subdirectory

any help greatfully received

here is my working script to archive separate files to separate archives at a file level in case it helps others

SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
SET /A COUNT=0
FOR /D /r %%F in ("") DO (
pushd %CD%
cd %%F
FOR %%X in (.*) DO (
SET /A COUNT+=1
REM ECHO !COUNT!
REM ENCRYPT SEQUENTIALLY RENAME FILE
"C:\Program Files\7-zip\7z.exe" a -t7z -r -mx3 -pdog -mhe=on %date:~-10,2%%date:~-7,2%%date:~-4,4%-!COUNT!.7z "%%X"
REM DELETE SOURCE FILE
DEL /F /S /Q /A "%%X"
)
popd
)

thx in advance ian

  • 1
    I'm not trying to be the party pooper but I think this would be magnitudes easier with a linux shell either on Linux or via CYGWIN or else you can use power-shell – arielnmz Mar 2 '15 at 23:51
  • @arielnmz why? so what if it is bat or bash. bash has more expert users but bat has enough – barlop Mar 3 '15 at 0:25
  • a generic way that is cheating a bit is to make a file listing all files with paths, then run regexes on it till it lists each individual 7z command then rename it as bat and run it. – barlop Mar 3 '15 at 0:42
  • the solution (i dont really know 7zip or cmd scripting much) is probably going to be replacing my FOR %%X in (.*) DO ( ... just with an alternative 7zip command line that zips up all the files in that directory and leaves the subfolders if there are any 7zip experts out there (fingers x) – ian Mar 3 '15 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.