-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZipAllFolders.bat
50 lines (39 loc) · 1012 Bytes
/
ZipAllFolders.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@echo off
setlocal EnableExtensions EnableDelayedExpansion
if not "%~1"=="" pushd "%~1" || exit /B 1
set "rmFolders="
choice /M "Remove original folders?"
if %errorlevel% == 1 set "rmFolders=y"
echo,
set /A "count=0"
for /D %%X in (*) do (
set /A "count+=1"
echo Folder !count!: %%X
7z.exe a "%%X.zip" -tzip -mx0 -r ".\%%X\*" > nul || exit /B 1
for /F "delims=" %%O in ("%%X.zip") do (
call :prettysize zipsize %%~zO
echo Size ~ !zipsize!
)
if defined rmFolders (
rmdir /S /Q "%%X"
echo Folder deleted.
)
echo,
)
echo Done.
pause
exit /B 0
rem Get human-readable size from bytes.
:prettysize & rem Args: 1:outputVariable 2:size
setlocal EnableExtensions EnableDelayedExpansion
set "unit=B"
set /A "size=%~2, roundup=0"
for %%U in (KB MB GB TB) do (
if !size! geq 1024 (
set "unit=%%U"
set /A "roundup = size & 512, size >>= 10"
)
)
if %roundup% gtr 0 set /A "size+=1"
endlocal & set "%~1=%size% %unit%"
exit /B 0