MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Lounge (https://www.mobileread.com/forums/forumdisplay.php?f=8)
-   -   Help Zipping subfolders (https://www.mobileread.com/forums/showthread.php?t=322638)

Tanjamuse 08-31-2019 08:08 AM

Help Zipping subfolders
 
Hello

I was hoping someone in here could help me with this problem:

I need to zip folders in a bunch of sub-folders.

Example:

Spoiler:

Root
Folder01
Subfolder 1
File1
File2
File3
Subfolder 2
File1
File2
Subfolder 3
File1
File2
File3
Folder02
Subfolder 1
File1
File2
File3
Subfolder 2
File1
File2


How it should be:

Spoiler:

Root
Folder01
SubFolder 1.zip
Subfolder 2.zip
Subfolder 3.zip
Folder02
SubFolder 1.zip
Subfolder 2.zip


I'm not that good with coding, but following a guide I managed to create this:

Code:

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\"
That zip's whatever's in the folder where it's placed, but I need it to go a level deeper like in the example above.

I know I can move it and run it separately in all the folders, but there are 3.000+ folders with 1.000.000+ subfolders distributed across.

I hope I make sense and someone can help me.

Thanks so much in advance.

Divingduck 09-01-2019 11:37 AM

Here is a possible solution.

With the given structure you need to delete all created zip files before you run it once more. Otherwise you will zip the before created zip files to additional archives. So, be careful if you like to do this with a huge amount of directories. Or better build a parallel structure to move all zip files to as this is better manageable.

Spoiler:
Code:

echo off
cls

Set _SourcePath="c:\Users\Armin\Documents\Calibre\Tanja\Calibre"
Set _7z="c:\Program Files\7-Zip\7z.exe"
Set _tmp="c:\temp"

For /R %_SourcePath% %%X in (.) do (

  REM Some checks for %%X (remove REM in lines below if needet)
  REM  echo X:          %%X
  REM  echo dX_LW:      %%~dX
  REM  echo pX:          %%~pX
  REM  echo dpX_Path:    %%~dpX
  REM  echo nX_Filename: %%~nX
  REM
 
  REM
  REM Check if directory include files
  REM Sample:
  REM if exist "%%~dpnX" dir /b /A:-d "%%~dpnX">nul 2>nul && @echo "%%~dpnX" is not empty
  REM
 
  if exist "%%~dpnX" dir /b /A:-d "%%~dpnX">nul 2>nul && @(
     
      REM
     
      echo %_7z% a -tzip "%%~nX.zip" "%%~dpnX\"
      REM Zip files from
      %_7z% a -tzip "%%~nX.zip" "%%~dpnX\" -w%_tmp%
     
      REM Move zip file to coresponding direktory
      move "%%~nX.zip" "%%~dpX"
      )
  )
 
Set _SourcePath=""
Set _7z=""
Set _tmp=""
 
echo on



Best regards, DD


All times are GMT -4. The time now is 09:04 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.