Today, shortly before weekend, I felt that pain again when seeing a PowerShell script. Somebody has literally raped the System.IO.DirectoryInfo across several pages and eternalised himself beyond anything related to aesthetics, technology or rationality. The aim of the script was to zip all the subdirectories of given folder one by one and push them to another drive with an ISO 8601-compliant timestamp prefix.
To ease the pain, here’s my decades-old snippet. Literally just in three lines. For better customisation, only the variables are separated:
@echo off set TheLogFile="d:\output.log" set ZipExecutable="c:\Program Files\7-Zip\7z.exe" set WatchPath=d:\daily set TargetPath=z: for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j set ldt=%ldt:~0,4%%ldt:~4,2%%ldt:~6,2% FOR /D %%I in ("%WatchPath%\*.*") do ( if EXIST "%WatchPath%\%%~nI" (%ZipExecutable% a -ssp -mx9 -mmt10 "%TargetPath%\%ldt%-%%~nI.7z" "%WatchPath%\%%~nI" -y >> %TheLogFile%) )
Have a nice weekend!