Holy cow. Google almost failed me. Almost.
Apparently, there are about a bajillion different methods for converting date/time to a text string. Most of the solutions I found were dependent on regional settings, were overly complex (in my opinion) or didn’t give me the format I wanted the date to be in OR didn’t give me a meaningful date at all.
After A LOT of trial and error, I finally stumbled upon this simple solution. (Source)
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "decrypted.txt" %%g-%%e-%%f.txt
It worked perfectly (i.e., the filename comes out as “2011-06-14.txt”). FTW!
So here’s what my batch file looks like (directory names have been changed, obviously);
cd c:\encryptedfiles\files echo mypassphrase|gpg --batch --passphrase-fd 0 --output decrypted.txt -d c:\encryptedfiles\files\*.gpg for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "decrypted.txt" %%g-%%e-%%f.txt move *.txt M:\decryptedfiles move *.gpg C:\encryptedfiles\files\archive
For those of you who prefer Windows Powershell, you can also do the same thing via a PS Script;
set-location "C:\encryptedfiles\files" $date = (Get-Date).ToString('yyyyMMdd') echo mypassphrase|gpg --batch --passphrase-fd 0 --output "$date.txt" -d "C:\encryptedfiles\files\*.gpg" Move-Item *.txt M:\decryptedfiles Move-Item *.gpg C:\encryptedfiles\files\archive
Not so painful!