Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: rename a file incremental number in batch file  (Read 3239 times)

0 Members and 1 Guest are viewing this topic.

dhuynh

  • Guest
rename a file incremental number in batch file
« on: April 18, 2006, 10:19:30 AM »
Hi All -

Can anyone please help me on a task that I been trying to figure out for days.  I have an XML file that gets created everytime I execute an Access program and this XML file get overwritten everytime I re-run the Access program.  However, I need to archive the XML file some I can do some reportings.  So my plan is to write a bacth file to 1st copy the XML file to another folder, 2nd rename it with an incremental number (ex. extract001.xml -- this the part I can't seem to figure out) , and 3rd launch the Access program and re-run it.

This is what I have so far.

XCOPY \\di-upload\di-st_perf\HealthCare-ID\Extraction_Batch.xml \\di-upload\perf_data\xml /s /y /d /i /h /c

REN \\di-upload\perf_data\xml\Extraction_Batch.xml "Extraction_Batch%5#.xml"


Any help or suggestion I greatly appreicated.

DosItHelp



    Intermediate
    Re: rename a file incremental number in batch file
    « Reply #1 on: April 20, 2006, 09:59:26 PM »
    dhuynh,

    Would it be ok to put a date-time-stamp in the fileneme?  If yes then referring to
    [highlight]http://dostips.cmdtips.com/DtCodeSnippets.php[/highlight] - Making a Unique String
    it will be a two liner:

    Code: [Select]
    for /f "tokens=2-8 delims=/:. " %%A in ("%date%:%time: =0%") do @set UNIQUE=%%C%%A%%B%%D%%E%%F%%G
    XCOPY \\di-upload\di-st_perf\HealthCare-ID\Extraction_Batch.xml \\di-upload\perf_data\xml\Extraction_Batch_%UNIQUE%.xml

    Your filename would be something like:
    Extraction_Batch_2006042023521504.xml

    Note very convenient:
    • You can order the destination directory by name and the files will appear in the order created
    • Based on the unique number you can easy see when you created the file, i.e.: YYYYMMDDhhmmssdd.
    • You run this every 0.01 second and still get unique file names.
    DOS IT HELP? ;)
    « Last Edit: April 20, 2006, 10:01:59 PM by DosItHelp »