Computing.Net > Forums > Programming > Batch File Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Help

Reply to Message Icon

Name: shmyrbob
Date: September 7, 2005 at 15:07:45 Pacific
OS: 98/2k/xp
CPU/Ram: 128-256
Comment:

I have looked through many batch file tutorials and web pages trying to figue out how I can use a batch file to create a directory with the current date and then copy some files to that directory.

Any idea's/suggestions would be greatly appreciated. Thanks




Sponsored Link
Ads by Google

Response Number 1
Name: Cache
Date: September 7, 2005 at 16:19:48 Pacific
Reply:

This may not be as trivial as it sounds, for a BATCH file at least.

The variable %date% can be used to output the current date but, the format of the output is where the problem starts.

The output from the command %date% would look like this: 08/09/2005

As you may know, the "/" character cannot be used in folder names. So using the output of %date% for a folder name would actually make a folder named something like "08" (without the quotes).

You would need to replace all assurances of / with a period, or similar legal char.


0

Response Number 2
Name: Cache
Date: September 7, 2005 at 16:23:22 Pacific
Reply:

oops lol, assurances = occurrences


0

Response Number 3
Name: uli_glueck
Date: September 8, 2005 at 00:16:07 Pacific
Reply:

This batch create directory for example:
08.09.2005
Replace the echo Command against the xcopy.


@echo off

date /t >date.txt


FOR /f "tokens=2 skip=2 delims= " %%a in ('find "." date.txt') do (

mkdir %%a
echo %%a

)

hope this helps
uli


0

Response Number 4
Name: shmyrbob
Date: September 8, 2005 at 07:27:13 Pacific
Reply:

Uli, I tried the code above and had to change the find "." to find " " to get the variable to contain the date, but it is still coming up in the xx/xx/xxxx format.

Thanks for your suggestions.


0

Response Number 5
Name: Mechanix2Go
Date: September 8, 2005 at 07:49:30 Pacific
Reply:

Hi uli,

That will work for 2k/xp, but not 9x.

In Nt there is a built-in %date%, so you just need to accomodate the layout.

My date layout is:

Thu 08-09-2005

So I can use this:

xcopy somefile %date:~10,4%%date:~7,2%%date:~4,2%\

[xcopy creates the directory for you]
###
I DOS and DOS based winders [3x 9x] it takes a little more doing.

This will get DAY, DATE & TIME into vars:

:: DDT-DOS.bat

echo.|date>datevar.bat
echo.|time>timevar.bat

echo set DATEvar=%%5>the.bat
call datevar

echo set DAYvar=%%4>the.bat
call datevar

echo set TIMEvar=%%4>the.bat
call timevar
:: done

As pointed out by Cache, there are some possible snags, not least is illegal chars.

Another is the verbage which is spewed out by the DATE and TIME commands.

It will vary widely with, among other things, language, version, codepage and regiomal settings.

To get a nice neat YYYYMMDD as my NT example, you need debug.

HTH



If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: uli_glueck
Date: September 9, 2005 at 04:33:36 Pacific
Reply:

Oh , sorry.
My NT4 date layout is Fr 09.09.2005 (european Version).
I don´t use the command line from Win9*.

Hi M2,
my not really working solution is a bit bumpy, not as elegant as yours. ;-)
I try to do to much with the For loop. But I do my best to learn.
Thanks a lot. :-))

Uli


0

Response Number 7
Name: robmc5
Date: September 21, 2005 at 07:54:16 Pacific
Reply:

Really just use this....

md c:\dirname\%Date:~-4, 4%%Date:~-10, 2%%Date:~-7, 2%

copy filename c:\dirname\%Date:~-4, 4%%Date:~-10, 2%%Date:~-7, 2%


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Help

batch file help www.computing.net/answers/programming/batch-file-help/13830.html

Batch File Help www.computing.net/answers/programming/batch-file-help-/11464.html

batch file help www.computing.net/answers/programming/batch-file-help/190.html