Created
February 15, 2015 06:39
-
-
Save CodeShane/78382349769e509659c3 to your computer and use it in GitHub Desktop.
Redirect command output to a file named as a prefix suffixed with the current date and time ( prefix_yyyy-mm-dd_hh-mm.txt )
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 | |
echo " " | |
echo " dtg.bat - Redirect command output to a file named as " | |
echo " a 'prefix' suffixed with the date ^& time group (DTG). " | |
echo " " | |
echo " Usage: dtg prefix <command [-params]> " | |
echo " Filename: prefix_yyyy-mm-dd_hh-mm.txt " | |
echo " " | |
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set thedate=%%c-%%a-%%b) | |
for /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set thetime=%%a-%%b) | |
set dtg = %thedate%_%thetime% | |
rem save first param | |
set first=%1 | |
rem accumulate 2nd+ params | |
shift | |
set params=%1 | |
:loop | |
shift | |
if [%1]==[] goto afterloop | |
set params=%params% %1 | |
goto loop | |
:afterloop | |
%params% > %first%_%thedate%_%thetime%.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment