Hey I have a batch script and I want to log it.
I want to produce 10 log files.
x1.log
x2.log
…
x10.log
there should only be max 10 log files in the folder the x1.log is always the newest log created.
that means the log files change name when the script runs.
x1.log becomes x2.log when the script runs and a new x1.log is created and x10.log is deleted because x9.log becomes x10.log
I hope I made it understandable.
Have a great day all
IF EXIST N:\projects\Trainee\work\st\M1_Infrastructure_Basics\log\x1.log (
ren "N:\projects\Trainee\work\st\M1_Infrastructure_Basics\log\x1.log" "x2.log"
break
ren "N:\projects\Trainee\work\st\M1_Infrastructure_Basics\log\x2.log" "x3.log"
) else (
echo "file nicht gefunden"
)
some code but it isnt the right way to solve it i figured out
>Solution :
You are making a typical mistake: imagine you have five files, x1.log, x2.log, …, x5.log, and you rename the way you do:
REN x1.log x2.log => x1 will not exist anymore and its contents are in x2
REN x2.log x3.log => x2 will not exist anymore and its content:
in fact the content of x1) will be in x3
...
=> You’ll end up with just one file, x5.log, containing the content of x1.log.
Therefore I would advise you to work in the opposite way:
REN x9.log x10.log
REN x8.log x9.log
...
Good luck 🙂