I run a script to download a file and unzip it. An import process then runs and leaves the files in their source location. I wrote the fully functioning code below to clean up that directory to be ready to use the next night.
I streamlined as much as I believe possible. I realize ~15 lines of code isn't exactly verbose or complicated and I've included the full script for reference. I feel, however, that specifically the second block - line
SET DATE= through line
DIR - can be better written but I don't know in what way. Am I simply seeing messy code where none exists? It just doesn't seem to 'read' well.
A note - the index.txt file is the same despite having two paths and is located in one or the other depending on the outcome (errors or not) of the import.
SET PATH="\\server\path\path2" IF NOT EXIST %PATH%\Upload.zip GOTO Done SET DATE=%date:~4,2%-%date:~7,2%-%date:~10,4% MKDIR %PATH%\Archives\%date% SET ARCHIVE=%PATH%\Archives\%date%\ DIR %PATH% /B > %ARCHIVE%log-%date%.txt MOVE %PATH%\Upload.zip %ARCHIVE%Upload-%date%.zip MOVE %PATH%\index.txt %ARCHIVE%index-%date%.txt ||( MOVE %PATH%\error_files\index.txt %ARCHIVE%index-%date%.txt ) DEL %PATH%\*.tif RMDIR %PATH%\error_files PUSHD %PATH%\Archives &&( FORFILES /S /D -15 /C "CMD /C IF @isdir == TRUE RD /S /Q @path" ) & POPD :Done