Jump to content

Recommended Posts

Posted

I was trying to write a simple batch script to automate an admin

process.

 

However whenever I try to use the %DATE% variable, it puts a space

after the actual date.

 

so if I did this

 

[h]MKDIR I:\system\%DATE%\code\com[/h] in a batch script

 

it would try and write out the command like:

 

MKDIR I:\system\03112008 \code\com ...see the space after the date?

 

I can't figure out how to get this to stop.

 

Any clues?

 

Thanks!

  • Replies 2
  • Created
  • Last Reply

Popular Days

Guest Pegasus \(MVP\)
Posted

Re: batch script issue

 

 

"cmt" <chrismtoth@gmail.com> wrote in message

news:0609dc8f-6a1f-4e57-9f22-6661e25beb32@q78g2000hsh.googlegroups.com...

>

> I was trying to write a simple batch script to automate an admin

> process.

>

> However whenever I try to use the %DATE% variable, it puts a space

> after the actual date.

>

> so if I did this

>

> [h]MKDIR I:\system\%DATE%\code\com[/h] in a batch script

>

> it would try and write out the command like:

>

> MKDIR I:\system\03112008 \code\com ...see the space after the date?

>

> I can't figure out how to get this to stop.

>

> Any clues?

>

> Thanks!

 

It seems you defined your own format for the %date% variable

in the Control Panel / Regional Settings. You need to check

the format there.

Guest John Toner [MVP]
Posted

Re: batch script issue

 

One way would be to use a for loop to parse out the extra characters and set

a new variable using only the portions of the DATE command that you want to

use. For example:

 

for /f "tokens=1-4 delims=/.- " %%A in ('date /t') do (set dte=%%B%%C%%D)

 

Now you could use %dte% to set your path using the date without spaces.

 

Regards,

John

 

Visit my blog: http://msmvps.com/blogs/jtoner

 

 

"cmt" <chrismtoth@gmail.com> wrote in message

news:0609dc8f-6a1f-4e57-9f22-6661e25beb32@q78g2000hsh.googlegroups.com...

>

> I was trying to write a simple batch script to automate an admin

> process.

>

> However whenever I try to use the %DATE% variable, it puts a space

> after the actual date.

>

> so if I did this

>

> [h]MKDIR I:\system\%DATE%\code\com[/h] in a batch script

>

> it would try and write out the command like:

>

> MKDIR I:\system\03112008 \code\com ...see the space after the date?

>

> I can't figure out how to get this to stop.

>

> Any clues?

>

> Thanks!


×
×
  • Create New...