I need to create a batch file that will:
1 . Make a backup of a file (say, “ren file.zip backup.zip”).
Then (using PKZip) compress a file and name it the same name as the file I just backed up in the previous step (“pkzip file.zip file.stv”)
Then open my FTP and make a connection. (Not as important, but hey, if I can it would be helpful).
Any ideas? I don’t thik I need ot “call” pkzip, do I? I mean in DOS, it’s not like I have top type “run pkzip” then zip the file, I can just do it all with the command “pkzip file.zip file.stv” (which is [program] [compressed file name] [source file] ).
How would I handle this in a batch file?
Batch files (under DOS) are simply commands that will be executed in order.
If you make a file backup.bat that contains the following
and another file called ftpcommands.txt containing
The, if you execute that file all the commands will be executed in order.
the -s flag to ftp will cause it to read commands from a file. (Note, I’m a bit rusty on my ftp commands under DOS, but I’m pretty sure that ti works like that.
copy ren file.zip backup.zip
pkzip fle.zip file.stv
winftp.exe (or whatever)
put all the above in notepad, and save as “Backup.bat”
Pretty much, put the exact items you type on a command line to do the functions. Assuming this batch file is called with a parameter being the file name (no extension) of the file to be backed up. (Backit.bat file)
Backit.bat file listing.
Copy %1.Zip %1Back.Zip
Pkzip %1.zip Knownfilename.txt
:End of file
You can even send text to the ftp app from a text file so if you had a text file like this
---- ftporders.txt Start -----
----- ftporders.txt end ----
Then on the ftp line it would read
There’s no error checking but it can speed things up.
All heck triple post
If you’re going to make a backup I don’t see why you need to copy the file. Just make the zip version. Your batch file would just have 2 lines:
PKZIP zname.zip fname
zname.zip is the output zip file name, fname is the file you want to back up, mycmds.txt contains a list of ftp commands that you want ftp to execute, such as
This combination of batch file and ftp command file would create a zipped backup of a file and archive it on the ftp server.
Make sure your path includes the directory in which pkzip.exe is. Otherwise add a path command to your .bat file, or copy the pkzip.exe file to the current folder.
Well, it’s been a few years since I’ve authored batch files (I miss that, ya know), but if pkzip is at the root of C, I think, and has a .exe file extention, there should be no need to use the call command.
Thanks everybody, I haveb’t time to do this today, but I’m a bit relieved now…
I need a backup because every week I create a new file. I want to keep the previous week’s file for one week. So, each time I rename the file as ‘backup.zip’, it’s actually the previous week’s data. Then, I create the new zip from the .stv file.
So at any given time I have the current week data, and a copy of last week’s data on file. (In case it gets corrupted or lost by the bean heads I FTP this stuff to).
the following batch file code will copy the supplied file
to a file with the date as a prefix :-
for /f "tokens=1 delims=.:/-, " %%u in (‘date /t’) do set $d1=%%u
if “%$d1:~0,1%” GTR “9” set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in (‘date /t’) do ( set dd=%%u
copy %1 %dd%%mm%%yyyy%%1
for %%u in ($tok $d1 dd mm yyyy) do set %%u=
If you save that as a file called (for example) save_as_date.bat
and call it with the following in your batch program :
it will create a file called 07082003file.zip
As it is, it leaves the original file so you can just delete that
or overwrite it.
bloody forum. why can’t i edit my last post ?!
Just ignore the
in the above post
HOW COME IT WORKED IN THAT LAST POST BUT NOT
THE PREVIOUS ONE ?!?!?!?!?!?!!
OK, i had a \ where i should have had a /
still doesn’t explain why i can’t edit my posts though …
Thanks. The edit option isn’t available. Lots of previous posts about it…I thought there was a sticky in ‘About this board’ about it, but i can’t find it.
Basically, it’s to avoid people flaming off, then going back and changing their OPs so they don’t look like an idiot.
Thanks again for that code!