I am trying to run a batch file, which runs an XSLT transformation against an XML file and writes out a second XML file.
This XML filename is determined by the following line in the batch file:
ICS_%DATE:~-4%_%DATE:~4,2%_%DATE:~7,2%_%TIME:~0,2%_%TIME:~3,2%_DATA.xml
When the time has a leading space (that is, any time before 10:00 am), the variable %TIME:~3,2%
returns a result with a leading space, which causes the filename to be truncated. The result file is empty.
If I run the batch after 10:00am, everything works fine. How can I generate a value similar to %TIME:~3,2%
that works before 10:00am?
Pressing "y" would use the goto command and go back to start and rerun the batch file. Pressing any other key would exit the batch file.
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
This will solve the space in the name issue, and replace it with a zero so it sorts correctly in a list.
set name=ICS_%DATE:~-4%_%DATE:~4,2%_%DATE:~7,2%_%TIME:~0,2%_%TIME:~3,2%_DATA.xml
set name=%name: =0%
How about this one ?
@ECHO OFF
FOR /F "tokens=1-4 delims=., " %%i IN ('DATE /t') DO SET cpdate=%%k_%%j_%%i
FOR /F "tokens=1-4 delims=:" %%b IN ('TIME /T') DO SET cptime=%%b_%%c
set filename=blabla_%cpdate%_%cptime%_%TIME:~-5,2%.xml
echo %filename%
The locale here is german, so you might have to adjust the order in "set cpdate..." for your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With