SaidbakR
SaidbakR

Reputation: 13534

Extra space between the dot of extension and the file name

I use the following code in Windows batch to generate file's names suffixed with the date and time.:

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-3 delims=/:/ " %%a in ('time /t') do (set mytime=%%a-%%b-%%c)
set mytime=%mytime: =% 

When I try to generate a file name like: ECHO DATABASE_2014-05-01_04-38-PM every thing works fine. However, when I try to add kind of extension to the file name such as .sql:

ECHO DATABASE_%mydate%_%mytime%.sql

I have got output like this: DATABASE_2014-05-01_04-31-PM .sql in-which an extra blank space is found between .sql and PM in the last of the file name.

How could I fix this issue to make the extension directly attached to the file name?

Upvotes: 1

Views: 95

Answers (1)

MC ND
MC ND

Reputation: 70923

set "mytime=%mytime: =%"

You have an aditional space at the end of the line. Quoting the assignment of the variable prevents this problem

Upvotes: 2

Related Questions