@ECHO OFF Rem -- Prepare the Command Processor SETLOCAL EnableExtensions EnableDelayedExpansion Title test7zip.bat Rev2c REM Uses standalone console version of 7-Zip to Zip files in user defined REM folder %zipdir% and move the zip archive to user defined folder %movedir% REM Added option for user to name archive file and completely empty zipdir 04-02-20 REM --------- Set path of console version 7-Zip (change as required) ---------- set path="F:\Utilities\7zipCommmandline_new\";%path% REM --------------------------------------------------------------------------- REM ---------- Set location of the folder to zip (change as required) --------- set "zipdir=c:\zipdir" REM --------------------------------------------------------------------------- REM ----- Set location of the folder to move archive (change as required) ----- set "movedir=c:\movedir" REM --------------------------------------------------------------------------- REM Check executable path, and existence of zipdir and movedir set /A "e=0" & set /A "z=0" & set /A "m=0" 7za.exe /? 2> NUL IF NOT %ERRORLEVEL%==9009 ECHO Executable path OK IF %ERRORLEVEL%==9009 ECHO 7za.exe does not exist in path && set /A "e=1" if exist "%zipdir%" if exist "%movedir%" ECHO zipdir and movedir OK if not exist "%zipdir%" ECHO zipdir doesn't exist && set /A "z=1" if not exist "%movedir%" ECHO movedir doesn't exist && set /A "m=1" if %e% == 1 goto end if %z% == 1 goto end if %m% == 1 goto end ECHO. REM -------------------------------------------------------------------------- REM Change working dir to %zipdir% pushd %zipdir% REM Replace space in hour with zero if it's less than 10 SET hr=%time:~0,2% IF %hr% lss 10 SET hr=0%hr:~1,1% REM This sets the date like this: mm-dd-yr-hrminsecs1/100secs Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2% REM Set name of archive for the contents of %zipdir% set myfolder= set /p myfolder=Enter an archive name for files and dirs in "%zipdir%": ECHO Directory to zip: %zipdir% ECHO Move archive to: %movedir% ECHO Archive Name: %myfolder% REM to zip only files change "%zipdir%" to "%zipdir%\*.*", "%zipdir%\*.txt", etc. ECHO. ECHO Zipping all contents of %zipdir% and moving archive %myfolder% to %movedir% ECHO. 7za a -tzip "%movedir%\%myfolder%_%TODAY%.zip" -r "%zipdir%\*.*" -mx5 ECHO. REM Delete entire contents of "%zipdir%" call:ask ECHO. ECHO Task Complete ... ECHO. ECHO Press any key to exit ... pause > NUL EXIT /B 0 :end ECHO. ECHO zipdir, movedir don't exist, or error in 7-Zip console version path ECHO Create zipdir, movedir, or correct executable path above ECHO Exiting script ECHO Press any key to exit ... pause > NUL ECHO EXIT /B 0 :ask set INPUT= set /p INPUT=Delete original files and dirs in "%zipdir%"^?(y/n): if not defined INPUT goto ask if /i "%INPUT:"=%"=="y" goto yes if /i "%INPUT:"=%"=="n" goto no echo Incorrect input, try again & goto ask :yes echo deleting contents from "%zipdir%" ... del /q "%zipdir%\*" for /d %%x in ("%zipdir%\*") do @rd /s /q "%%x" goto :eof :no echo. echo No files or dirs deleted from "%zipdir%" goto :eof