Urgent :Batch file for rename and copy the log file

Posted on 2007-10-01
Last Modified: 2011-09-20
Hi all,
I have a log file called "hr_xms_interface_vb.log" in D:\hr_xms_prog.
I have batch file which runs every day and gives me this log file (hr_xms_interface_vb.log).
That part works fine.

 But now i want to copy this log file to D:\hr_xms_prog\hr_xms_interface_log_backup folder.
and to rename it as hr_xms_interface_vb_001.log(For back up purpose). Next time when i run the batch file, i want the latest log file as hr_xms_interface_vb_001.log and the previous log file as(old log file) hr_xms_interface_vb_002.log. and so on.
I have to keep 5 days log file as back up. So in 6 th time,hr_xms_interface_vb_005.log has to be deleted and all others to be renamed correspondingly.

Could you please help me to write a batch file for doing this?

Thanks in Advance.

Question by:noble123_2000
    LVL 51

    Accepted Solution

    del  D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_005.log
    move D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_004.log D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_005.log
    move D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_003.log D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_004.log
    move D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_002.log D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_003.log
    move D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_001.log D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_002.log
    copy hr_xms_interface_vb.log D:\hr_xms_prog\hr_xms_interface_log_backup\hr_xms_interface_vb_001.log
    LVL 63

    Expert Comment

    Not sure if Move is the correct command, I would think that ren  ( rename )  would be more appropriate.

    I hope this helps !

    Author Comment

    hi all,
    Thanks Ahoffmann and SysExpert for your fast reply.
    Ahoffmann , Your solution is Perfect and thanks a lot!

    SysExpert , Move works fine for me...

    Thanks all

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now