All pastes #2072395 Raw Edit

Something

public text v1 · immutable
#2072395 ·published 2011-05-30 17:33 UTC
rendered paste body
@echo off

:: Creates a RAR archive of files/directories if they are smaller than a
:: given limit and moves the files to a specified directory.

Setlocal
Setlocal EnableDelayedExpansion

:: size of rar archives in kilobytes
set /a rarsize_kb=200000

:: files/dirs smaller than this (in kilobytes) don't get packed
set /a rarlimit_kb=1000000

:: directory to move files to
set target_dir="C:\UPLOAD"


call :loop %*
goto :EOF

:loop
if "%~1"=="" goto :EOF

::::: Find size of argument :::::
set /a filesize=%~z1/1024
set /a total=filesize
FOR /R %1 %%F IN (*) DO (
	set /a filesize=%%~zF/1024 
	set /a total=!total!+!filesize!
)

::::: move if smaller than limit, otherwise pack :::::
IF !total! lss %rarlimit_kb% (
	move "%~f1" %target_dir%

) ELSE (
	"%ProgramFiles%\WinRAR\Rar.exe" a -k -y -rr -ep1 -m0 -v%rarsize_kb% -w"%~dp1" "%~f1.rar" "%~f1"
	move "%~f1*.rar" %target_dir%
)

shift
goto :loop