Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating a Batch file that produces max 10 log files and deletes the oldest

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading