Skip to content

Instantly share code, notes, and snippets.

@jkonrath
Last active August 4, 2020 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkonrath/25188b7d8d59cd55b5843e0e557c06c6 to your computer and use it in GitHub Desktop.
Save jkonrath/25188b7d8d59cd55b5843e0e557c06c6 to your computer and use it in GitHub Desktop.
Windows CMD to make a timestamped directory
@echo off
:: Windows CMD - Make a timestamped directory, prefixed with the first argument.
:: i.e. pass in "proj1" and it creates a directory named "proj1-2020-08-02_09-01-00"
:: It shouldn't be this hard, but it is.
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
set "outdir=%1-%fullstamp%"
mkdir %outdir%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment