1.

Solve : Create the file name with the date?

Answer»

Dear All

I want to create the file to call a number of the batches file to run the schedule job with the file name, the output result with the name date format (e.g. abc_20131023.xml).

Besides, I want to the script clear the file name before generate the report.

Can you please let me know the script can handle this task ?

Thanks 
I do not know the format of a .xml, but you can ACCESS the date by using the variable %date%.  To help further we would need to know what 'echo %date%' outputs on your computer as it differs. Below is an example that would work on my machine that should help you puzzle your way through it.

output:
Code: [Select]C:\windows\system32>echo %date%
10/22/2013 Tue

code:
Code: [Select]for /f "tokens=1 delims= " %%A in ("%date%") do (
for /f "tokens=1-3 delims=/" %%B in ("%%A") do (
set m=%%B
set d=%%C
set y=%%D
) )
set prefix=abc
set ext=xml


set name=%prefix%_%y%%m%%d%.%ext%

OR
[/code]
for /f "tokens=1,2 delims==" %%A in ('wmic path win32_localtime get month^, day^, year /value') do set %%A=%%B
set prefix=abc
set ext=xml


set name=%prefix%_%Year%%Month%%Day%.%ext%

::May not work, requires wmic
[/code]The first FOUR lines of this code will give you reliable YY DD MM YYYY HH Min SEC variables in XP Pro and higher.

Your description is very vague but this has lines below which delete a file if it EXISTS or not, so you can create new DATA in the same filename.

Code: [Select]echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
echo fullstamp: "%fullstamp%"

del "c:\path\to\folder\abc_%datestamp%.xml" 2>nul

echo do something with "c:\path\to\folder\abc_%datestamp%.xml"

pauseThank you all of your  guys I use this and it works
Code: [Select]echo. 2>date.txt
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "date.txt" %%e-%%f-%%gdatet.txtThank you brotherdeja vu



Discussion

No Comment Found