today dir: retrieve, store, use

B

Bertoldino

hi
I'd like to use robocopy for some automated backups
my problems:

robocopy seems not to create the destination directory, so I have to create
it before starting copy jobs
I want to create these directories with names like "YYYY_MM_DD_HHMM" (e.g.
2008_02_19_1455)

how can i retrieve these informations, transform them in one variable and
then use it for creation of the directory and next copy job?

my flow: retrieve YYYY, MM, DD, HH, MM; create YYYY_MM_DD_HHMM , store it in
a variable %todaydir%, MD \mypath\%todaydir% ; robocopy source
\mypath\%todaydir%

but... i don't know how to retrieve these values :-/

thanks for your time
 
P

Pegasus \(MVP\)

Bertoldino said:
hi
I'd like to use robocopy for some automated backups
my problems:

robocopy seems not to create the destination directory, so I have to
create
it before starting copy jobs
I want to create these directories with names like "YYYY_MM_DD_HHMM" (e.g.
2008_02_19_1455)

how can i retrieve these informations, transform them in one variable and
then use it for creation of the directory and next copy job?

my flow: retrieve YYYY, MM, DD, HH, MM; create YYYY_MM_DD_HHMM , store it
in
a variable %todaydir%, MD \mypath\%todaydir% ; robocopy source
\mypath\%todaydir%

but... i don't know how to retrieve these values :-/

thanks for your time

Your observation is incorrect: robocopy.exe will happily create
the target folder if it does not exist. Try the following batch file:
@echo off
set YYYY=%date:~-4%
set mm=%date:~-7,2%
set dd=%date:~-10,2%
set hh=%time:~0,2%
set min=%time:~3,2%
robocopy d:\temp d:\%YYYY%_%mm%_%dd%_%hh%%mm% *.txt

Depending on your regional settings, you may have to modify the
offsets for mm and dd in order to get the desired mm_dd order.
 
B

Bertoldino

Pegasus (MVP) wrote:

Your observation is incorrect: robocopy.exe will happily create
the target folder if it does not exist.

oh my!
thanks Pegasus!
Try the following batch file:
@echo off
set YYYY=%date:~-4%
set mm=%date:~-7,2%
set dd=%date:~-10,2%
set hh=%time:~0,2%
set min=%time:~3,2%
robocopy d:\temp d:\%YYYY%_%mm%_%dd%_%hh%%mm% *.txt

Depending on your regional settings, you may have to modify the
offsets for mm and dd in order to get the desired mm_dd order.

many thanks!

and what if i want to use the weekday ?

in italy if i ask for TIME /T the day is like "mar" "mer" "ven" "gio" and so
on.
i suppose in english OS it would be like "wed" "sun" "sat" and so on...

:)
 
B

Bertoldino

Bertoldino wrote:

many thanks!

and what if i want to use the weekday ?

in italy if i ask for TIME /T the day is like "mar" "mer" "ven" "gio"
and so on.
i suppose in english OS it would be like "wed" "sun" "sat" and so
on...

sorry, what I said is not correct; first of all, the command is obviously
DATE (not time)
weekday is shown on my workplace OS, but not at home.

and... i can't remember what I did to obtain this information using DATE /T

anyway, I'd like to obtain weekday information and use it as you shown me
with other infomation :)

(sorry for my "funny" english...)
 
P

Pegasus \(MVP\)

Bertoldino said:
Bertoldino wrote:



sorry, what I said is not correct; first of all, the command is obviously
DATE (not time)
weekday is shown on my workplace OS, but not at home.

and... i can't remember what I did to obtain this information using DATE
/T

anyway, I'd like to obtain weekday information and use it as you shown me
with other infomation :)

(sorry for my "funny" english...)

There is nothing wrong with your English!

There are several ways to resolve your problem:
a) You could modify the regional settings so that the environmental
variable %date% includes the weekday. This is not a robust
method and it can generate different results for different users.
b) You can modify the registry in the locations below. This is also
not a robust method.
HKEY_USERS\.DEFAULT\Control Panel\International (regional, idate)
HKEY_CURRENT_USER\Control Panel\International
c) You can use one of the many "now.exe" utilities and extract
your information from its output. This works fine but every
machine must have the same flavour of now.exe.
d) You can run a VB Script. This would be the most robust
solution but it gets a bit chatty.
 
B

Bertoldino

Pegasus said:
There are several ways to resolve your problem:
b) You can modify the registry in the locations below. This is also
not a robust method.
HKEY_USERS\.DEFAULT\Control Panel\International (regional, idate)
HKEY_CURRENT_USER\Control Panel\International

Hi Pegasus,
why is that method not robust?

does it vary between nt, 2000, xp, vista and servers?

:-|
 
P

Pegasus \(MVP\)

Bertoldino said:
Hi Pegasus,
why is that method not robust?

does it vary between nt, 2000, xp, vista and servers?

:-|

Because it is user-specific and because some applications
appear to change the settings behind your back. I run a very
clean machine, yet I have lost the "Day-of-week" part in the
%date% variable on several occasions. A robust method
works no matter what!
 
B

Bertoldino

Pegasus said:
Because it is user-specific and because some applications
appear to change the settings behind your back. I run a very
clean machine, yet I have lost the "Day-of-week" part in the
%date% variable on several occasions.

i understand :-(
A robust method
works no matter what!

of course I agree with you :)
i'm trying not to mix "batch" and WSH ... of course because I'm not able
making nothing but "msgbox" with WSH , he he... ;-)

Thanks Pegasus. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top