need a programmer for simple task

ThePiston

Senior member
Nov 14, 2004
861
0
76
I'm making a scheduled task out of a .cmd file and this is what I have so far for creating a directory:

md D:\OfficeMate_"date"

Where "date" is I would like the actual date to be inserted. What's the correct parameter for that?
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
md D:\OfficeMate_%date:~4,2%-%date:~7,2%-%date:~10%

%date% is an enviroment variable that would output the date as "Fri 12/30/2005", you can try it by doing "echo %date%".

But because the output has backslashes in it, you need to do a substring and parse only the numbers.
 

ThePiston

Senior member
Nov 14, 2004
861
0
76
WobbleWobble, thanks, your code did something, but I don't know what.... nothing happened in the D directory.

Shuxclams, thanks, but that script just created this folder: "OfficeMate_0".
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
When you type the following, what do you see? I noticed that my work computer outputs "Fri 12/30/2005" while my home computer outputs "30/12/2005". That's likely because of regional settings. It makes a difference because we're manipulating specific positions of the string.

Type the following from the code box in a command prompt
 

ThePiston

Senior member
Nov 14, 2004
861
0
76
WobbleWobble, it echos "12/31/2005"

SHUX, I tried it as a .bat file and changed the E:\ to D:\ and it still just gives a folder named "OfficeMate_1" with a folder inside that one named "-00-". I'm running XP Pro. Any ideas?
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
Now try " echo %date:~0,2%-%date:~3,2%-%date:~6% "

That should give you 12-31-2005, if so, then you can go "md D:\OfficeMate_%date:~0,2%-%date:~3,2%-%date:~6%"

Shuxclams's code extends it a bit futher by checking if folder exists. It'd be what's in the code box.

The other simple way of doing it is simply changing your Regional Settings in Windows. Change the date seperator from "/" to "-", since you can't have "/" in files names. That way you can simply use "md %date%"
 

Shuxclams

Diamond Member
Oct 10, 1999
9,286
15
81
Not sure why it is giving you that error, or misname. I suspect it is possibly part of the timezone issue, I use this on our network which is Win2K/XP mixed in AD. I'll look into it some more however....









SHUX
 

Shuxclams

Diamond Member
Oct 10, 1999
9,286
15
81
Originally posted by: WobbleWobble
Now try " echo %date:~0,2%-%date:~3,2%-%date:~6% "

That should give you 12-31-2005, if so, then you can go "md D:\OfficeMate_%date:~0,2%-%date:~3,2%-%date:~6%"

Shuxclams's code extends it a bit futher by checking if folder exists. It'd be what's in the code box.

The other simple way of doing it is simply changing your Regional Settings in Windows. Change the date seperator from "/" to "-", since you can't have "/" in files names. That way you can simply use "md %date%"


Funny thing is when I reformat the example I get a folder named 'OfficeMate_Sa- 1-' So there you have it.



SHUX
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
I think it's a regional settings issue. The text he gets from a %date% is different than yours.

What do you get when you do a echo %date% Shux?
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
That's why the code may not work for you, because when I do an echo %date% I get "02/01/2006". Just change the locations of the substrings and it'll work for anyone else. :)

Be sure to test it on the actual systems you'll be deploying it on, as you may also run into these differences. I'm sure someone else can create a script to replace the "/" with "-" by doing a find, rather than absoute substring.
 

ThePiston

Senior member
Nov 14, 2004
861
0
76
Success! thanks guys, here is final code if anyone is searching on this:
@Echo OFF
set dd=%date%
IF NOT EXIST "D:\OfficeMate Backups\OfficeMate %date:~0,2%-%date:~3,2%-%date:~6%" md "D:\OfficeMate Backups\OfficeMate %date:~0,2%-%date:~3,2%-%date:~6%"

xcopy D:\desktop\*.* "D:\OfficeMate Backups\OfficeMate %date:~0,2%-%date:~3,2%-%date:~6%\*.*" /s /e /h /v /d /i /r /y