In these exercies you will learn how to use some useful DOS programs together with
batchfiles.
- Write a batchfile that copies all files with the postfix .cpp, .doc and .xls
from a floppy disc to a corresponding directory hierarchy on the hard disc. This batchfile is useful for example
in transferring files from computer lab to your own computer. Copying individual files on Windows can be
an annoying exercise. When writing the file pay attention to this:
- Using XCOPY is clever.
- The directory hierarchy of the hard disc is not known so it has to be given as a parameter.
- To avoid errors make the batchfile to test whether the target folder already exist or not.
- The files are copied only if they are later versions than the ones on the hard disc or if they are
completely new. Testing the date is not possible in all cases so the batchfile has to test if there has been any
changes in the file. Testing is done by using file attributes so read the help to find out what attributes to use
with the command.
Save the batchfile as harddisc.bat and test it.
An example: harddisc U:\systems\
- Write another version that copies the files from a directory on the hard disc to a floppy disc.
Otherwise the batchfile should be as the one above.
An example: tofloppy U:\systems\
What problems there might be with using the batchfile? How would you solve them?
-
Get a DOS based anti-virus program to your computer from
<URL:
ftp://ftp.europe.f-secure.com/anti-virus/free/>.
The program file is a zip file called fp-308.zip. Save it to U:\systems\.
Now let's write some batchfiles that make it easier to unzip and use the anti-virus program.
- The first job is to unzip the program file by using a DOS based program pkunzip.
By writing the name of the progran on the Command Prompt you'll get the help for the program. A brief
instruction for using PKZIP and PKUNZIP is available at the end of
lecture 3.
Write a batchfile for unzipping. By using this batchfile you don't have to remember the parameters
for the program every time.
- The first parameter for the batchfile is the name of the file to be unzipped.
- The second parameter is the folder where to extract the files from the zip file.
- Save the batchfile as
unzip.bat and test it.
An example: unzip fp-308.zip fprot
- The anti-virus program can be used in the DOS user interface but in the following you
will use the program straight in the Command Prompt.
Write a batchfile that deletes viruses without asking the user for confirmations.
Help for F-prot parameters is available by using the command f-prot /?.
- Viruses must be scanned from the whole hard disc.
- The batchfile has to be such that one can scan the computer without understanding a thing of the
process.
- Save it as scan.bat and test it.
The batchfile above is useful when you give an anti-virus program to a friend who knows nothing
about it.
An example: scan
- Now you have a batchfile you can give for you friends to use. The batchfile has to be in the
same package as the anti-virus program. The program is too large for one floppy disc so it has to be packed
on several ones. This time we use the ARJ programme for compressing.
Write a batchfile that compresses the files and subfolders in a directory given as a parameter and
makes floppy disc sized packages of them. Then it is easy to copy the compressed files to a floppy disc.
By writing the name of the ARJ program on the Command Prompt
you'll see the help for the program. Brief instrucions for using ARJ is found at the end of
leture 3.
An example: compressARJ file_or_directory
-
Write a batchfile that uncompresses the packages. Save it as
uncompressARJ.bat.
An example: uncompressARJ package
On the last disc there is usually space for the batchfile and you may also need to include ARJ.
You can also write short instructions and include them in the disc:
- Copy the contents of the floppy discs to a directory on the hard disc.
- Open Command Prompt and go to the directory where you copied the files into.
- Use command uncompressARJ to run the batchfile that uncompresses the files. The
name of the package to be uncompressed is included in the batchfile.
- Run the anti-virus programme by using the command scan.
- If you repeatedly copy files between your computer and a server you can make it easier by writing
a batchfile for it and by saving it to the U: drive.
Plan and write a batchfile for copying files between a server and your computer. Note that
usernames and passwords must never be asked on a batchfile!. For brief instrictions for using SCP
see the end of lecture 3.
An example: copy_p2c server_directory local_directory
- Are the batchfiles you wrote of any use for you? Can you think of a situation
where you could use them?