log of what my batch file did, not commands

April 20, 2011 at 10:55:59
Specs: Windows XP
::This takes txt files located in a directory c:\new and while making a copy in the
::directory c:\import it appends the date to the file name in the format _YYYYMMDD
::A log file is created but it just says files copied
::I would like the log file to list the newly copied files that have the date appended. See code. Thanks!!

**************code**********************
@Echo Off

:start
cls
set /p input= This program appends date to your filenames, do you want to continue (y/n)?:
if /i "%input%" equ "y" goto :AppendDate
if /i "%input%" equ "n" goto :ExitScreen
echo Invalid choice & pause & goto start


@Echo On

:AppendDate
echo Success! Dates Appended. See log file AppendlogYYYYMMDD.log for details.
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @(
Set FileDate=%date:~10%%date:~4,2%%date:~7,2%
)
@For %%a in (c:\new\*.txt) do copy %%a "c:\import\%%~na_%FileDate%.*">>c:\Appendlog%date:~10%%date:~4,2%%date:~7,2%.log
pause
exit

:ExitScreen
echo Dates will NOT be appended to filenames
pause
exit


See More: log of what my batch file did, not commands

Report •

#1
April 20, 2011 at 14:08:02
okay, I got some help on another thread and I've pasted the edited code below that address my original question. Plus I was repeating code that I had already set in FileDate and cleaned that up a bit.

********code**********
@Echo Off

:start
cls
set /p input= This program appends date to your filenames, do you want to continue (y/n)?:
if /i "%input%" equ "y" goto :AppendDate
if /i "%input%" equ "n" goto :ExitScreen
echo Invalid choice & pause & goto start


@Echo On

:AppendDate
echo Success! Dates Appended. See log file AppendlogYYYYMMDD.log for details.
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @(
Set FileDate=%date:~10%%date:~4,2%%date:~7,2%)
if exist c:\Appendlog%Filedate%.log del /q /F c:\Appendlog%Filedate%.log
@For %%a in (c:\new\*.txt) do ((echo copying "%%a" to "c:\import\%%~na_%FileDate%.txt" >>c:\Appendlog%Filedate%.log ) && (copy "%%a" "c:\import\%%~na_%FileDate%.txt" >>c:\Appendlog%Filedate%.log ))
pause
exit

:ExitScreen
echo Dates will NOT be appended to filenames
pause
exit


Report •
Related Solutions


Ask Question