Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File... please help 1

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I've created a batch file that copies two .MDB files to a Zip disk. It creates a new directory on the Zip disk and copies the files into it.

What I would like to do is call the new directory by todays date (i.e. in the mm-dd-yy format) and then copy the specified files into the newly made directory. How do I call the directory by the date and in turn, how do I move the files to that new directory if the ever changing date specifies the name of the directory?

any ideas guys?

thanks in advance,

Marcus
 
hi marcus

my solution goes back a few years into batch file heaven, but it gives you something that is close to what you want. maybe there is a more modern easier way someone can suggest.

my solution

to get (something) like this done, you are going to have 3 separate batch files.

the first batch file will basically create the second batch file on the fly. (i will call this batch file ONEBAT.BAT)

the second batch file (called TWOBAT.BAT) when executed will pass five separate parameters, and it's the fifth (or last) parameter that you are interested in.

the third batch file (MUST be called CURRENT.BAT) then creates the directory to allow you to copy the files into that directory. you can put any commands you like into this batch file to complete your backup

as the second batch file is created by the first batch file, I won't bother describing its contents, you can play and see how it works

ONEBAT.BAT
echo | more | date > twobat.bat
twobat

CURRENT.BAT
md %4
cd %4
dir

the content that i have shown in CURRENT.BAT is very basic, and you would need to add your backup commands in here after the first two lines.

if you need more explanation, i'd be happy to help



Pete Bloomfield
Down Under
 
Thanks Pete... things have slightly changed. I now use pkzip to compress the two files which I transfer to the Zip disk. Is the renaming process the same in principle for directories and files?

Sorry, but could you explain twobat.bat etc... I'm not very experienced about these things. How does the date variable transfer into current.bat for naming purposes and how do you change the date format?

Also this may sound stupid but what does % do in a batch file?

Thanks in advance,

Marcus
 
Marcus

You can rename files ok in a batch file, but not directories (to my knowledge, some one else might be able to confirm this).

You could zip your files in ONEBAT.BAT, and then copy them to the zip disc in CURRENT.BAT.

If you ran ONEBAT.BAT, you will see that the contents of TWOBAT.BAT is just the same as you would get by typing "DATE" at the dos prompt, and pressing enter.

The "ECHO |MORE" is used to replicate the pressing of the 'enter key' in the batch file, and the results are piped (>) to the TWOBAT.BAT file. That's how the date variable is transferred into the CURRENT.BAT.

The '%4' is a replaceable parameter. Notice the first line of TWOBAT.BAT. The first parameter passed to it by ONEBAT.BAT is "current". Follow the line along, and you see the fifth (%4) and last parameter is the date.

As far as changing the date format, I'm not aware that you can, certainly not using this method.

Your questions aren't stupid, so don't worry 'bout that. :)




Pete Bloomfield
Down Under
 
An alternate method:
a file "one.bat" that contains the following
gwbasic getdate (assuming that you can get gw or q or another basic)
copy sourcefilename /v


and the GWBASIC file getdate.bas
open"o",1,"dirdate.dat" (for historic purposes)
a$=left$(date$,2)+mid$(date$,4,2)+mid$(date$,7,4) (parses date to 8 characters)
print #1,a$
close 1
f$="drive:\"+a$
chdir f$
system


gets the date and moves to the subdirectory by that name then completes the batch file. Ed Fair
efair@atlnet.com

Any advice I give is my best judgement based on my interpretation of the facts you supply.

Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top