I have a need to append a timestamp to block of code that does a move and a block of code that does a copy.
I've been able to acheive my goal do if know hte file names, such as this:
Code: Select all
FOR /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set timestamp=%%a%%b)
FOR /f "tokens=* delims= " %%c in ("%timestamp%") do (set timestamp=%%c)
::-- Setting PEMFIN Error Path --::
FOR /D %%f IN (%MAINPATH%%ERRORPATH%PEMFIN_Errors\) DO (
::-- Setting PEMFIN Error File Names --::
FOR %%b IN ( PEMFIN_dataload_adminfct.txt PEMFIN_dataload_adminfx.txt PEMFIN_dataload_empfct.txt PEMFIN_dataload_empfx.txt ) DO (
::-- Making Error File Archive Directory --::
IF NOT EXIST "%MAINPATH%%ERRORPATH%PEMFIN_Errors\%date:~-4,4%_%date:~-10,2%%date:~-7,2%" MKDIR "%MAINPATH%%ERRORPATH%PEMFIN_Errors\%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
::-- Copy all *.err files to archive directory and append timestamp --::
ECHO F | XCOPY /F "%%f%%b" "%MAINPATH%%ERRORPATH%PEMFIN_Errors\%date:~-4,4%_%date:~-10,2%%date:~-7,2%\%%~nb_%timestamp%%%~xb"
)
)
But, having trouble adapting these (2) portions of code to use the method above. These are pieces of coee I have in a lot of my scripts:
Code: Select all
FOR %%f IN (%MAINPATH%%LOGPATH%*) DO (
IF NOT EXIST "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" MKDIR "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
MOVE %%f "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
I also use:
Code: Select all
FOR %%f IN (%MAINPATH%%LOGPATH%*) DO (
IF NOT EXIST "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" MKDIR "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
Copy %%f "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)
I believe the wildcards are giving me trouble tying to append a time stamp to them. Thank you!