Last active
August 29, 2015 13:56
-
-
Save jtbrough/9196216 to your computer and use it in GitHub Desktop.
Prepending or appending a datetime stamp using Batch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem set general variables | |
set input_files=*.txt | |
rem set date/time variables (generates yyyy-mm-dd_hhmmss) | |
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set file_date=%%c-%%a-%%b) | |
for /f "tokens=1-3 delims=:." %%a in ("%TIME%") do (set file_time=%%a%%b%%c) | |
set date_time=%file_date%_%file_time% | |
rem appends _yyyy-mm-dd_hhmmss after file name (before extension) to all filed matched by input_files | |
for %%a in (%input_files%) do ren "%%~a" "%%~na_%date_time%%%~xa" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem set general variables | |
set input_files=*.txt | |
rem set date/time variables (generates yyyy-mm-dd_hhmmss) | |
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set file_date=%%c-%%a-%%b) | |
for /f "tokens=1-3 delims=:." %%a in ("%TIME%") do (set file_time=%%a%%b%%c) | |
set date_time=%file_date%_%file_time% | |
rem prepends yyyy-mm-dd_hhmmss_ before full file name (including extension) to all filed matched by input_files | |
for %%a in (%input_files%) do ren "%%~a" "%date_time%_%%~nxa" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment