Monday, June 6, 2011

How to create this batch file in DOS?

I need help creating a batch file in DOS for one of my classes. I have watched tutorials and asked my classmates and I still can't figure it out. This is what is required:



(2). Create a file called 1.BAT in the A: root directory that will perform the following tasks:



1. Do not allow ANY commands to be displayed on the screen.

2. Change your directory to the root directory of the A: drive

3. Change your directory to the MYWP subdirectory.

4. Clears the screen.

5. Displays the contents of the file MYWP.TXT

6. Pause until user strikes any key.

7. Returns to the root directory of the A: drive.

8. Clear the screen and display the MENU.TXT file screen again.





This is what I have in the batch file:



echo off

f:

cls

dir /MYWP

type MYWP.txt

pause

f:

menu.bat



What am I doing wrong? When I try to execute the batch file, I get ';Invalid switch MYWP';.How to create this batch file in DOS?
You want this slash \ for MYWP

dir \MYWP



This is what you need. Try it out:



@echo off

a:

cd \

cd MYWP

cls

type MYMP.TXT

pause

cd \

cls

type MENU.TXTHow to create this batch file in DOS?
CD MYWP rather than DIR /MYWP



DIR would list the contents and /MYWP is an invalid switch to the DIR command. the / denotes the switch



F: should be A: right? Since you want to be scanning the floppy?

Add ';cd \ '; after F: line to force return to root. Otherwise, if the letter had been accessed before it may bring up a subfolder
echo off

cd..

a:

cls

cd MYWP

type MYWP.txt

pause

a:

menu.bat
The ';dir'; command does not take you to a directory, but rather display the one you are currently in. To change to the directory ';mywp'; you need the command ';cd'; (for Change Directory).



Also you do not need the / in front of the name. A / in Dos means that whatever follows it is going to be a ';switch'; for the dir command. As there is no such switch as ';MYWP';, you are getting that error.



Change the line to: cd MYWP
Open a text editor.



Type in:



@echo off

A:

cd \

cd mywp

cls

type mywp.txt

pause

cd \

cls

type menu.txt



Save it as 1.bat to the A: drive.
echo off

a:

cd MYWP

cls

type MYWP.txt

pause

cd ..

cls

type MENU.txt

No comments:

Post a Comment