New
#1
Batch file renaming files but not double
Hello,
Got another batch file question.
I think I`m close but I`m overlooking something.
I have some logging that will get the date of today when I log off.
But now if I log off twice the file won`t rename, filename already exists.
So I came with a script to just add a number behind the file if it already exists.
And here is the problem it doesn`t work but I can`t seems to find out why it won`t work.
Hopefully an extra pair of eyes can help me out
This is what I got so far:
@ echo off
set jaar=%date:~9,4%
set maand=%date:~6,2%
set dag=%date:~3,2%
set restartvar=1
if exist "D:\test\HardwareMonitoring %jaar%-%maand%-%dag%.txt" (
goto restart
) else (
goto shutdown
)
:restart
if exist "D:\test\HardwareMonitoring %jaar%-%maand%-%dag% [%restartvar%].txt"(
set /A restartvar=%restartvar%+1
goto restart
) else (
ren "D:\test\HardwareMonitoring.hml" "HardwareMonitoring %jaar%-%maand%-%dag% [%restart%].txt"
)
:shutdown
ren "D:\test\HardwareMonitoring.hml" "HardwareMonitoring %jaar%-%maand%-%dag%.txt"
The first file that is in that folder just renames so no problems there.
It seems there is a problem in the restart loop.
Hope that you can find the solution to my problem