1.

Solve : rename a file incremental number in batch file?

Answer»

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.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? ;)


Discussion

No Comment Found