Dos batch file
Author
Discussion

rodney59

Original Poster:

424 posts

278 months

Tuesday 6th December 2005
quotequote all
In the good old days (10 years ago) I could probably have knocked this off without blinking. However working on many other (and better) OS I've forgotten.

Can anybody help me. O/S is win2K.

I need to provide a user with a simple way to copy her documents to a CD. (floppy disk too small). she backs up daily, and wants a history of the docs at the end of each day.

Now what I thought was a simple dos batch file could do this. What I want is something along the lines of:

get O/S date in format DD/MM/YY etc.
set variable xyz to be DDMMYY
create directory %xyz%
copy files to dir

done.

Now the problem I have are lines 1 and 2 above. How can I get the OS date and create a dir called DDMMYY ?

many thanks.


scared but happy

24,147 posts

259 months

Tuesday 6th December 2005
quotequote all
Can you show us what you have so far?

it used to be something like MD c:\%var%

rodney59

Original Poster:

424 posts

278 months

Tuesday 6th December 2005
quotequote all
I'm game!

This is a cross between DOS and another OS I know.

cd Documents and SettingsMy Documents
echo.
echo. %DATE%
echo.
echo Insert a CD
echo.
set D substr(%DATE%,4,2)
set M substr(%DATE%,6,2)
set Y substr(%DATE%,8,2)
set DMY concat(%D%%M%%Y%)
mkdir %DMY%
pause
verify on
copy *.doc d:\%DMY%
echo.
echo.
echo Backup complete. Check that there are no errors reported on screen here.

something along those lines......

jamieboy

5,929 posts

259 months

Tuesday 6th December 2005
quotequote all
Not sure that substr is valid in batch files, is it? Something like this would be dead easy in VBScript, though, and if she's running Windows 2000 I'd suggest that would be a better way.

If you do a quick google for scripting.filesystemobject you should see how to do the file copy, and googling for the datepart() function should help with converting the date to a string in the correct format.

The site www.devguru.com/technologies/vbscript/home.asp is a pretty handy resource for the various VBScript objects and functions.

Plotloss

67,280 posts

300 months

Tuesday 6th December 2005
quotequote all
Try this

for /f "tokens=1,2,3 delims=/" %%a in ('date /t') do set date=%%a%%b%%c
md %date%
CD %date%

This creates a directory called todays date in DDMMYYYY format and changes to that directory.

But once you've got the date variable filled with todays date everything else you need should be easy.

rodney59

Original Poster:

424 posts

278 months

Tuesday 6th December 2005
quotequote all
Plotless how you remembered that I'll never know!
Minor mod and I'm away:
for /f "tokens=1,2,3,4 delims=/ " %%a in ('date/t') do set date=%%b%%c%%d

as DOS returns Tues 06/12/2005 as the date.

Many Many thanks....