Ms Dos Basics Assignment

Ms Dos Basics Assignment Words: 7474

Learning MS-DOS Basics CONTENTS 1. Overview2 2. MS-DOS Commands. 2 2. 1. Internal commands2 2. 2. External Commands2 3. The Command Prompt3 4. Typing a Command3 5. Viewing the Contents of a Directory3 5. 1To view the contents of a directory one screen at a time4 5. 2To view the contents of a directory in wide format5 6. Changing Drives5 7. Changing Directories6 7. 1Changing directories6 7. 2Changing Back to the Root Directory7 8. Creating a Directory7 9. Deleting a Directory8 10. Copying Files9 10. 1Copying a Single File9 10. 2Copying a Group of Files9 11. Renaming Files10 2. Deleting Files11 12. 1Deleting a Group of Files11 12. 2To delete a directory11 13. Check the Date and Time11 14. Recall a DOS Command11 15. Create a File with DOS11 16. To check the contents of a file12 17. Editing Text Files12 18. Checking the Condition of a Disk12 19. Help13 20. Using The ATTRIB Command13 21. The COLOR Command14 22. Symbols used with commands15 23. The PATH Command16 24. The EXIT Command16 25. Batch Files17 25. 1Requirements for Creating batch files17 25. 2How to create a batch file17 25. 3Working with arguments18 25. 4The Rem statement19 25. Prompting for user input19 25. 6How to start Windows files and other programs from a batch file20 25. 7Conditional branching with “If” statements20 25. 8″If exist” statement20 25. 9The “goto” command22 25. 10Iterating with “For”24 26. Other Important MS-DOS Commands28 This tutorial gives you an opportunity to try basic MS-DOS commands. Overview Most Personal Computers run under the MSDOS Operating System. MSDOS being the Microsoft Disk Operating System. The Operating System has three main constituents:- • The system files which are hidden. Perform – basic tasks e. g. eading the keyboard, displaying characters on the screen, opening and closing files etc. • The command interpreter (CMD. EXE) – which reads commands typed at the keyboard and attempts to obey them. It has some simple commands built in – these are known as internal commands. • A series of utility programs covering functions not handled by the internal commands. The exact number of external commands varies between different versions of MSDOS. MS-DOS Commands. A command is the name of a special program that makes your computer carry out a task. There are two types of MS-DOS commands – internal and external. Internal commands Internal commands are built into the operating system as part of a file called CMD. EXE. They are loaded into memory whenever you switch on your computer. When you type an internal command, MS-DOS performs it immediately. Some of the MS-DOS internal commands are listed below. Small reference of internal DOS commands 1. del, erase – delete files 2. rd, rmdir – delete directories 3. dir – show content of directories 4. cd, chdir – change current directory 5. cls – clear the screen 6. md, mkdir – create a directory 7. copy – copy of one or several files 8. ren, rename – rename of files or directories . type – shows the content of text files 10. vol – shows the name of the storage drive 2 External Commands Files with extension COM or EXE are external commands. Because these commands are files, they are not built into the operating system ( these are the commands that alter between versions of MS-DOS) . The MS-DOS external commands may contain SOME or all of the following, Small reference of external DOS commands • attrib – shows the attributes of files or set one of those • fdisk – partitioning or modify of the hard disk • move – move of files • mem – shows the occupancy of working memory tree – shows the directory structure When you type an external command, MS-DOS looks for the command in the current directory. If it is not there, you must guide MS-DOS to the relevant directory with the PATH command. The Command Prompt When you first turn on your computer, you will see some cryptic information flash by. The operating system displays this information to let you know how it is configuring your computer. When you go to the command prompt you will see the following: C:> This is called the command prompt. The flashing underscore next to the command prompt is called the cursor.

The cursor shows where the command you type will appear. If your command prompt does not look like the example, type the following at the command prompt, and then press ENTER: cd .. If your command prompt still doesn’t look like the example, type the following at the command prompt, and then press ENTER: prompt $p$g Your command prompt should now look like the example. Typing a Command Type the following at the command prompt (you can type the command in either uppercase or lowercase letters). If you make a typing mistake, press the BACKSPACE key to erase the mistake, and then try again.

Don’t waste your time!
Order your assignment!


order now

You must press ENTER after every command you type. ver The following message appears on your screen: Microsoft Windows XP [Version 5. 1. 2600] The ver command displays the version number of the operating system. Viewing the Contents of a Directory In this section, you will view the contents of a directory by using the dir command. The dir command stands for “directory. ” To view the contents of a directory type the following at the command prompt: dir A list similar to the following appears: [pic]This is called a directory list. A directory list is a list of all the files and subdirectories that a directory contains.

In this case, you see all the files and directories in the main or root directory of your drive. All the files and directories on your drive are stored in the root directory. A list of the files in the directory appears, but scrolls by too quickly to read. You can modify the dir command so that it displays only one screen of information at a time. 1 To view the contents of a directory one screen at a time dir /p When you typed the dir command this time, you included the /p switch after the command. A switch modifies the way MS-DOS carries out a command.

Generally, a switch consists of a forward slash (/) that is followed by one or more letters or numbers. When you used the /p switch with the dir command, you specified that MS-DOS should pause after it displays each screen of directory list information. The p actually stands for “page” Another helpful switch you can use with the dir command is the /w switch. The /w switch indicates that MS-DOS should show a wide version of the directory list. 2 To view the contents of a directory in wide format dir /w The directory list appears, with the filenames listed in wide format. Note that only filenames are listed.

No information about the files’ size or date and time of creation appears. If the directory contains more files than will fit on one screen, you can combine the /p and /w switches as follows: dir /w /p Changing Drives This section describes how to change drives. Changing drives is useful if you want to work with files that are on a different drive. So far, you have been working with drive C. You have other drives you can use to store information. For example, drive Z is your home drive. To change to and view files on a different drive type the following at the command prompt: z:

Note that the command prompt changed NB: There must be a disk in the drive that you want to change to. The drive letter that appears in the command prompt shows which drive is the current drive. Unless you specify otherwise, any commands you type are carried out on the current drive and in the current directory. So far, all the commands you typed were carried out on the current drive and in the current directory. You can also carry out a command on a drive that isn’t current. For example, you can view the files on a disk in drive A without switching to drive A by following this procedure.

To view files on drive Z when drive C is current Type the following at the command prompt: dir z: By specifying z: after the dir command, you are giving MS-DOS additional information. You are indicating that you want the dir command to show the list of files and directories on drive Z instead of drive C. The z: you typed after the dir command is called a parameter. A parameter specifies what a command should act on. In the previous example, the parameter you used indicated which directory list you want to view. The following procedure presents another example of using a parameter. dir c:BUS5110

A list of the files in the BUS5110 directory on drive C should scroll past on your screen. The c:dos parameter specifies that you want MS-DOS to display the contents of the DOS directory on drive C, even though your command prompt may indicate that you are on a different directory. Changing Directories 1 Changing directories All the names that have beside them are directories. To change directories, you will use the cd command. The cd command stands for “change directory. ” To change from the current directory to the BUS5110 directory type the following at the command prompt: cd BUS5110

The command prompt changes. It should now look like the following: C:BUS5110; The command prompt shows which directory you are in. In this case, you know you successfully changed to the BUS5110 directory because the command prompt displays the directory’s name. Now the current directory is BUS5110. NOTE: To change to a directory in a different drive: Method 1 1. Change to that required drive 2. Use the CD command to change to the required folder Method 1 Combine the two by omitting the CD command e. g from your home folder type C: WINDOWS 2 Changing Back to the Root Directory

Next, you will change from the current directory to the root directory. The root directory is the first directory in a drive. To change to the root directory from any directory type the following at the command prompt: cd Note that the slash you type in this command is a backslash (), not a forward slash (/). No matter which directory you are in, this command always returns you to the root directory of a drive. The root directory does not have a name. It is simply referred to by a backslash (). The command prompt should now look like the following: C:> To go back one directory at a time use the following command cd..

This command takes you one directory back (this may not necessarily be the root). Notice it is different from the cd command which always takes you back to the root. When the cd command is followed by two periods (.. ), MS-DOS moves up one level in the directory structure. In this case, you moved up one level from the GRAPES directory to the FRUIT directory. Creating a Directory In this section, you will create two directories. Creating a directory is helpful if you want to organize related files into groups to make them easy to find. To create a directory, you will use the md command. The md command stands for “make directory. Type the following at the command prompt: md fruit You have now created a directory named FRUIT. To see the new FRUIT directory type dir command. Exercise create a new directory within the fruit directory called GRAPES To confirm that you successfully created the GRAPES directory, type the following at the command prompt: dir A list similar to the following appears: [pic] Note that there are three entries in the FRUIT directory. One is the GRAPES directory that you just created. There are two other entries—one looks like a single period (. ) and the other looks like a double period (.. ).

These directory entries are important to MS-DOS, but you can ignore them. They appear in every directory and contain information relation to the directory structure. Exercise – Change to the GRAPES directory, To switch back to the FRUIT directory, type the following: cd .. Deleting a Directory If you no longer use a particular directory, you may want to delete it to simplify your directory structure. Deleting a directory is also useful if you type the wrong name when you are creating a directory and you want to delete the incorrect directory before creating a new one. In this section, you will delete the GRAPES directory.

Exercise: Before you begin this section, change to the fruit directory: C:FRUIT> To delete a directory, use the rd command. The rd command stands for “remove directory. ” Type the following at the command prompt: rd grapes Note You cannot delete a directory if you are in it. Before you can delete a directory, you must make the directory that is one level higher the current directory. Copying Files To copy a file, you will use the copy command. When you use the copy command, you must include two parameters. The first is the location and name of the file you want to copy, or the source.

The second is the location to which you want to copy the file, or the destination. You separate the source and destination with a space. The copy command follows this pattern: copy source destination 1 Copying a Single File Examples: • Create a notepad file called lesson1. txt and store it in drive c: Type the following: copy c:lesson1. txt c:fruit • A file can also be renamed while coping (equivalent to save as) as follows: copy C:WINDOWSSystem32 AUTOEXEC. NT to Z: AUTOEXEC. TXT 2 Copying a Group of Files In this section, you will use wildcards to copy a group of files from the DOS directory to the FRUIT directory.

Wildcards are symbols that enable you to perform operations on more than one file at a time by giving MS-DOS a pattern to match. MS-DOS searches for any file whose filename or extension matches the pattern. There are two wildcard characters: 1. ?  – A question mark in a filename or extension means that up to a maximum of ONE character/letter/number can occupy that position. 2. * – An asterisk in a filename or extension means that any number of characters/letters/numbers, (up to maximum of EIGHT before the dot, and up to  a maximum of THREE after the dot) can occupy that position.

NOTE:- There can be LESS than the maximum number of characters/letters/numbers Renaming Files To rename a file, you will use the ren command. The ren command stands for “rename. ” When you use the ren command, you must include two parameters. The first is the file you want to rename, and the second is the new name for the file. You separate the two names with a space. The ren command follows this pattern: ren oldname newname Deleting Files This section explains how to delete, or remove, a file that you no longer want on your disk. If you don’t have very much disk space, deleting files you no longer use is essential.

To delete a file, you will use the del command. The del command stands for “delete. ” To delete a file called Lesson1. txt del lesson1. txt 1 Deleting a Group of Files In this section, you will use wildcards to delete a group of files. To delete files in the current directory that end with the extension doc using wildcards A list of all the files that end with the extension OLD appears. Make sure that these are the files you want to delete. When you are deleting files by using wildcards, this step is very important. It will prevent you from deleting files accidentally. del *. txt To delete a directory

Remove the FRUIT directory by typing the following at the command prompt: rd fruit NB: Ensure that the directory is empty first! Non empty directories cannot be deleted. Check the Date and Time • DOS will let you check or change the date and time once it has been set. The procedure to do this is to type: date and press return. If the correct date is displayed, simply press return. If the date is incorrect, type the correct date and press return. • Similarly type: time and press return. If the correct time is displayed, simply press return. If the time is incorrect, type the correct time and press return.

Recall a DOS Command The F3 function key can be used to recall the last DOS command you typed in. If you would like to retrieve a previously entered command, you can also press the up arrow key continuously until you reach the desired command you were looking for. After you use the F3 key to recall a command, you can use the backspace key to edit any part of the command or add to your command. You can also type out each letter in your last command by using the right arrow key or the right cursor key. Create a File with DOS Type: copy con Lesson3. txt Type this message in the following format: Bob

Sales are up 15%. Good Job! Craig Press the F6 function key (^Z) and press return. DOS gives you a message that 1 File(s) has been copied. If you open the file in windows you will notice that it has the data you keyed in. To check the contents of a file If you need to check the contents of a particular file, you will need to use the TYPE command. Type: type lesson3. txt. DOS prints the contents of the file. NOTE: The TYPE command will not work for all files, especially files that have the . com, . exe, . sys, and . bas extensions. These are program files and will only display junk on the screen.

Editing Text Files At the command prompt type Edit lesson1. txt The MS-DOS Editor will now display in the Command Prompt Window. Type some text inside the editor window. Now click on “File” and then on “Save”. Checking the Condition of a Disk You use the CHKDSK command to: • Check a disk to see how much space there is available, and how much is in use. This is an example of a file without errors [pic] This is an example of a file with errors [pic] • To fix some disk errors, such as files that show a non-zero size but that really have no data in them use a /F switch CHKDSK J: /F

The /F option ensures that it fixes any errors it can. Help If you want help on a topic, then you must type the command, followed by a space and then a slash and question mark. To get help on, say, the DIR command, you would type: DIR /? Using The ATTRIB Command The ATTRIB command is used to set file attributes like making a file read-only or make it a hidden file. All the different file attributes is listed below: R      Read-only file attribute. A      Archive file attribute. S      System file attribute. H      Hidden file attribute. Type Dir at the Command Prompt and make sure that the files “Lesson1. xt” are present. At the Command Prompt type: Attrib +r Lesson1. txt The file should now be a read-only file. If you should open this file in Notepad in Windows, you will see that you can make changes to it but you will not be allowed to save it under the same name. At the Command Prompt type Attrib -r lesson1. txt The read-only attribute should now be removed from the file. Under normal circumstances you should never have to use the “System File Attribute” as this is reserved for system files. Therefore the only other attribute that is worth mentioning is the “Hidden File Attribute”.

At the Command Prompt type: Attrib +h Lesson. txt Type the Dir command and notice the file will not be listed. In Windows you will not be able to find the file if “Folder Options” is set to “Do not show hidden files and folders”. If the “Folder Options” is set to “Show hidden files and folders” then you will be able to see the file even if its hidden attribute is set. At the Command Prompt type Attrib -h Lesson1. txt to remove the hidden attribute. Exercise: Unhide the file The COLOR Command Use the COLOR command to set the default console foreground and background colors.

Below is a list of hex digits that represents certain colors. 0 = Black 1 = Blue 2 = Green 3 = Aqua 4 = Red 5 = Purple 6 = Yellow 7 = White 8 = Gray 9 = Light Blue A = Light Green B = Light Aqua C = Light Red D = Light Purple E = Light Yellow F = Bright White Type: COLOR 3f at the command prompt and press the “Enter” key to set the console background color to aqua and the foreground color to bright white. To reset the console foreground and background colors to its default state just type COLOR without any argument at the command prompt and press the “Enter” key. Symbols used with commands

In addition to the commands discussed earlier, there are several symbols that are used to modify or combine the actions of commands. For example the redirection symbol “>” is frequently used to save some output to a text file instead of directing it to a screen. Type: Dir c: ; list. txt The table below gives a list of some common symbols that are used: |Symbols used with commands | |Symbol |Function |Example |; |Sends output to a named file. If file does not exist, it creates one. Overwrites existing file |command ; somefile | | |e. g. dir c: ; list1. txt | | |;; |Appends output to contents of a named file or creates a file if none exists |command ;; somefile | | |e. . dir z: ;; list1. txt | | |; |Uses contents of a named file as input to a command |command ; somefile | | |e. g. sort ; list1. txt | | | |more ; list1. xt | | | |sort ; names. txt ; list. txt | | |¦ |Sends (“pipes”) the output of command1 to the input of command2 |command1 ¦ command2 | | |e. g. type list1. xt ¦ more | | | |dir z: | sort | | | |dir c:windows | sort ; list2. txt | | |& |Used to combine two commands.

Executes command1 and then command2 |command1 & command2 | | |e. g. dir c: ; list3. txt & dir z: ;; list3. txt & type list3. txt | | |&& |A conditional combination. Executes command2 only if command1 completes successfully |command1 && command2 | | |e. g. . dir x: ;; list3. txt & type list3. xt | | | |would still work despite the error in the first command. | | | |dir b: ;; list3. txt && type list3. txt | | | |The use of && in the later statement prevents this | | |¦¦ |Command2 executes only if command1 does not complete successfully. |command1 ¦¦ command2 | | |e. . . dir c: ¦¦ dir | | | |Notice in the example the last command does not execute because the previous one executed | | | |dir x: ¦¦ dir | | |@ |Used in batch files at the beginning of a line to turn off the display of commands |@echo off | The PATH Command

The PATH command is used to set or display the search path for executable files. If the Command Prompt were currently at “C:MainDir>” and you typed Edit to launch the MS-DOS Editor, the Command Interpreter (command. com in earlier OS versions or lately cmd. exe) would not have been able to find the MS-DOS Editor program if not for the PATH statement. Type PATH at the Command Prompt and press the “Enter” key. All the different search paths will be listed. So when you type Edit at the Command Prompt the Command Interpreter will search through all these paths to find the Edit Program.

Typing path gives one of the execution paths as e. g. inside c:windowssystem32 you will find the file sort. exe The EXIT Command To exit the Command Prompt session type Exit and press “Enter”. Batch Files Batch files are a quick and efficient way to automate MS-DOS tasks or commands. Systems administrators are well aware of the utility of batch files but the average PC user is generally unacquainted with them. This is unfortunate since it means that many are foregoing the use of a powerful tool for carrying out routine or repetitive tasks.

Although batch files can be quite sophisticated and used for complicated network and system administration, they can also be of the utmost simplicity and very brief. Here, I introduce the batch file and discuss some uncomplicated examples that make basic tasks easier. 1 Requirements for creating batch files There are five basic requirements for the structure of any batch file: 1. It must be a pure ASCII file, meaning that no characters other than the commands you give, plus carriage returns, can be used in the file. 2. The filename can be any legal filename, but cannot have the same name as a . COM or .

EXE file in the same directory, or the same name as any DOS internal command, such as COPY or DIR. 3. It must have the extension . BAT. 4. The file must have an end-of-file marker following the last command in the file. 5. Each command must be on a separate line in the batch file, separated from adjacent commands by a carriage return. 2 How to create a batch file • Type Edit at the Command Prompt and press “Enter”. • In the MS-DOS Editor enter the following lines of text exactly as shown below with each command on a separate line. (Press the “Enter” key when at the end of a line). MD MainDir CD MainDir MD SubDir1 MD SubDir2 In the MS-DOS Editor click on “File” then click on “Save”. • Next to the “File Name” label type mybatch. bat • click on OK. • Exit the MS-DOS Editor • At the Command Prompt type mybatch and press the “Enter” key. The batch file will execute and firstly create the “MainDir” directory in the root of the current drive. Then it will do a change directory to “C:MainDir>”. After that it will create “SubDir1” and “SubDir2” in the parent directory “MainDir” by using the MD (Make Directory) command. If you do a Dir now you will notice that you are already in the “MainDir” parent directory and the 2 created subdirectories is present. Note that the names “MainDir”, “SubDir1” and “SubDir2” I’m using is just to make explaining the exercises easier. You may use any name you desire. The first line in a batch file often consists of this command @echo off By default, a batch file will display its commands as it runs. The purpose of this first command is to turn off this display. NB: Complete paths must be used when referring to a file in a batch script. Solution [pic] 3 Working with arguments The above exercise can be improved by making a batch file that is able to list whatever folder we want.

Batch files can use arguments or data that is input from the user. The process makes use of placeholders of the form %1, %2. These are replaced in the script. This type of situation cannot be mimicked directly by clicking in windows. It has to be run in a command prompt hence the advantage of batch files. @echo off dir %1 To run the batch file you can type the following at the prompt to display the contents of a directory called books. Z:> lesson2. bat Books We can also use our redirection symbols to put the list wherever we want. . The new batch file would be @echo off ir %1 > %2 To run the batch file you can type the following at the prompt to write the contents of a directory called books in a file called List4. txt. Z:> lesson2. bat Books list4. txt 4 The Rem statement Very often batch files contain lines that start with “Rem”. This is a way to enter comments and documentation. The computer ignores anything on a line following Rem. For batch files of any complexity, comments are a good idea. Note that the command interpreter actually reads Rem statements so using too many can slow down execution of a script. 5 Prompting for user input

You can also interact with a user and ask that data be entered. The syntax is: set /p variable= [string] • “Variable” is the name of the variable that will be assigned to the data that you want the user to input. • “String” is the message that the user will see as a prompt. If desired, “string” can be omitted. Here is an example that asks the user to enter his or her name: set /p name=What is your name? This will create a variable name whose value is whatever the user enters. Note that the user must press the “Enter’ key after typing the input. To use the variable: Echo Your name is %name%

The /P switch allows you to set the value of a variable to a line of input entered by the user. It will display the specified promptString before reading the line of input. The promptString can be empty. 6 How to start Windows files and other programs from a batch file To run Microsoft Windows programs or files use the START command. The below example would run Windows Notepad. START NOTEPAD. exe or START /max NOTEPAD. exe The /max makes it start the window Maximized. @ECHO OFF start mspaint. exe start notepad. exe start wordpad. exe start calc. exe 7 Conditional branching with “If” statements

Although many useful tasks can be carried out with simple batch files containing just a few lines, the full power that is available can only be realized with the more advanced methods of branching, iterating, and looping. These methods are among the tools used by programmers to create very sophisticated scripts. The actual syntax is If (condition) (command1) Else (command2) The “Else” part is optional. 8 “If exist” statement There is a special “If exist” statement that can be used to test for the existence of a file, followed by a command. An example would be: Using If Only

If exist somefile. ext del somefile. ext Example If exist list. txt echo File Found Solution If exist %1 echo File Found You can also use a negative existence test: if not exist somefile. ext echo no file Example If not exist z:list. txt echo File Not Found or If not exist %1 echo File Not Found Using If-Else If exist %1 (echo File Found) else (echo File Not Found) Or If exist %1 (echo %1 Found) else (echo %1 Not Found) 9 The “goto” command Generally, the execution of a batch file proceeds line-by-line with the command(s) on each line being run in turn.

However, it is often desirable to execute a particular section of a batch file while skipping over other parts. The capability to hop to a particular section is provided by the appropriately named “goto” command (written as one word). goto :label The target section is labeled with a line at the beginning that has a name with a leading colon. :label The label can be a line anywhere in the script, including before the “goto” command. “Goto” commands often occur in “if” statements. For example you might have a command of the if (condition) goto :label Example:

Create a batch file that asks the user for a file to search for and informs the user if the file was found or not. It should give the user an opportunity to search for as many files as the user would like to. @ECHO OFF :point1 Set /p file=Enter File Name If exist %file% (echo File Found) else (echo File Not Found) Set /p ans=Search again? Y/N If %ans%==Y (GOTO :point1) The “End of File” (:eof) label for exiting a script Sometimes it is desirable to terminate a script if a certain condition is met (or not met). One way to exit is to use the special label :eof in a goto command. f you need to test for a particular condition that makes script termination desirable, you can write: if (condition) goto :eof 10 Iterating with “For” Computers are very good at doing the same thing over and over. The command line contains a powerful and versatile method for carrying out this type of operation. With this method, you can automate many time-consuming tasks. The basic statement is of the form: for {each item} in {a collection of items} do {command} A single-letter replaceable variable is used to represent each item as the command steps through the collection (called a “set”).

Note that, unlike most of Windows, variables are case-dependent. Thus “a” and “A” are two different variables. The variable has no significance outside the “For” statement. I will be using X throughout the discussion but any letter will do. The variable letter is preceded with a single percent sign when using the command line directly or double percent signs in a batch file. Thus the statement in a batch file looks like this: for %%X in (set) do (command) Simple iteration through a list Example: the set could be a list of files: for %%X in (file1 file2 file3) do command or %%X in (lesson1. txt lesson2. txt lesson3. txt) do type %%X NB: Wildcards can be also be used to denote a file set. For example: for %%X in (*. jpg) do command This will carry out the command on all files in the working directory with extension “jpg”. Switches used with For A number of switches or modifiers are available to help define the type of items in the set. The table below lists the switches. They are listed in upper case for clarity but are not case-sensitive. |Switch |Function | |/D |Indicates that the set contains directories. |/R |Causes the command to be executed recursively through the sub-directories of an indicated parent | | |directory | |/F |Parses files or command output in a variety of ways | I will consider a number of examples that illustrate the use of “For” and its switches. Working with directories If you wish to use directories in the variable set, use the switch /d. The form of the command is for /d %%X in (directorySet) do command.

An example that would list all the directories (but not sub-directories) on the C: drive is for /d %%X in (C:*) do echo %%X Solution: for /d %%X in (*) do echo %%X for /d %%X in (test*) do echo %%X Recursing through sub-directories If you want a command to apply to the sub-directories as well as a parent directory, use the switch /r. Then the command has the form: for /r %%X in (set) do command Note that you can designate the top directory in the tree that you want to work with. This gets around the often cumbersome problem of taking into account which is the working directory for the command shell.

For example the statement: for /r z: %%X in (*. txt) do echo %%X [pic] IST 3020 – PRINCIPLES OF OPERATING SYSTEMS Assignment I (You are required to submit this Assignment) Example Write a batch script for each of the following tasks: 1. Changes to a user specified Directory, Displays the Files and Subdirectories inside it. 2. Changes to a user specified Directory and Displays the contents of a user specified File 3. Changes to a user specified Directory and Displays the contents of a user specified File or directory inside it 4. Moves Up One Directory Level Displays Directory on a Cleared Screen. 5.

Copies All or Specified Files From the c: Drive Root to z: 6. Deletes files from the Current Directory with Prompts and Warnings 7. Deletes Specified Directory and All Files and Directories Below Prompts “Are You Sure? ” Before Deletion Commences. 8. Asks the user for a file name, and then searches for the file. It should informs the user of the location of the file if found or advice the user that the file was not found. It should allow the user to search for as many files as the user wishes to. Other Important MS-DOS Commands I’m not going to talk about the FDISK and FORMAT command in this tutorial.

These command used to be very important in preparing your hard disk before loading Windows 98 or previous versions. With the widespread use and easy installation procedures of Windows XP these commands have dropped in importance as Windows XP basically leads you through the process. NB: The commands discussed here are for your information only. You do not have to memorize them. Assoc: Displays or modifies file name extension associations. Used without parameters, assoc displays a list of all the current file name extension associations.

At: Schedules commands and programs to run on a computer at a specified time and date. You can use at only when the Schedule service is running. Used without parameters, at lists scheduled commands. Attrib: Displays, sets, or removes the read-only, archive, system, and hidden attributes assigned to files or directories. Used without parameters, attrib displays attributes of all files in the current directory. Comp: Compares the contents of two files or sets of files byte by byte. Comp can compare files on the same drive or on different drives, and in the same directory or in different directories.

When comp compares the files, it displays their locations and file names. Used without parameters, comp prompts you to enter the files to compare. Cprofile: Cleans specified profiles of wasted space and, if user-specific file associations are disabled, removes these associations from the registry. Profiles that are currently in use are not modified. Defrag: Locates and consolidates fragmented boot files, data files, and folders on local volumes. Driverquery: Displays a list of all installed device drivers and their properties. Fc: Compares two files and displays the differences between them.

Fc can even resynchronize files if there is a mismatch. Find: Searches for a specific string of text in a file or files. After searching the specified file or files, find displays any lines of text that contain the specified string. Getmac: Returns the media access control (MAC) address and list of network protocols associated with each address for all network cards in each computer, either locally or across a network. Helpctr: Starts Help and Support Center. Used without parameters, helpctr displays the Help and Support Center home page.

Hostname: Displays the host name portion of the full computer name of the computer. Ipconfig: Displays all current TCP/IP network configuration values and refreshes Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) settings. Used without parameters, ipconfig displays the IP address, subnet mask, and default gateway for all adapters. Irftp: Sends files over an infrared link. Used without parameters or used with /s, irftp opens the Wireless Link dialog box, where you can select the files that you want to send without using the command line.

Lpq: Displays the status of a print queue on a computer running Line Printer Daemon (LPD). Used without parameters, lpq displays command-line help for the lpq command. Mmc: Opens Microsoft Management Console (MMC). Using the mmc command-line options, you can open a specific MMC console, open MMC in author mode, or specify that the 32-bit or 64-bit version of MMC is opened. More: Generally used along with other commands, displays one screen of output at a time. Move: More convenient than copy-paste. Moves one or more files from one directory to the specified directory.

For example, you have some Excel files having their names start with “MonthlyReport” in your My Documents folder which you want to move to a separate folder. Using the Windows XP Explorer, you would have to manually select every single file and then use cut-paste. Using the move command to perform the same task is much simpler and easier. Type the following command and hit enter: move MonthlyReport*. xls c:MonthlyReports Msinfo32: Displays a comprehensive view of your hardware, system components, and software environment. Netstat: This command is very useful to diagnose slow internet connections.

It displays active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics (for the IPv6, ICMPv6, TCP over IPv6, and UDP over IPv6 protocols). Used without parameters, netstat displays active TCP connections. Openfiles: Queries or displays open files. Also queries, displays, or disconnects files opened by network users. Ping: Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message Protocol (ICMP) Echo Request messages.

The receipt of corresponding Echo Reply messages are displayed, along with round-trip times. Ping is the primary TCP/IP command used to troubleshoot connectivity, reachability, and name resolution. Used without parameters, ping displays help. Recover: Recovers readable information from a bad or defective disk. Runas: Allows a user to run specific tools and programs with different permissions than the user’s current logon provides. Shutdown: Allows you to shut down or restart a local or remote computer.

Used without parameters, shutdown will logoff the current user. Start: Starts a separate Command Prompt window to run a specified program or command. Used without parameters, start opens a second command prompt window. Systeminfo: Displays detailed configuration information about a computer and its operating system, including operating system configuration, security information, product ID, and hardware properties, such as RAM, disk space, and network cards. Taskkill: Ends one or more tasks or processes. Processes can be killed by process ID or image name.

Tasklist: Displays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer. Tree: Graphically displays the directory structure of a path or of the disk in a drive. Ver: Displays the Windows XP version number. Vol: Displays the disk volume label and serial number, if they exist. A serial number is displayed for a disk formatted with MS-DOS version 4. 0 or later. W32tm: A tool used to diagnose problems occurring with Windows Time. Xcopy: Copies files and directories, including subdirectories. ———————–

Exercise: 1. Display the contents of c: drive from your home directory 2. Display the contents of WINDOWS directory in c: drive from your home directory 3. Display the contents of Documents and Settings directory in c: drive from your home directory 4. Display the contents of My Documents directory in c: drive from your home directory Exercise: 5. Display the files in your home directory in lower case 6. Display only directories in your home folder 7. Display files in the WINDOWS directory of c: sorted by file type Exercise: 8. Change directory back to your home directory . Change directory to a folder in your home directory 10. Change directory back to the root 11. Change directory to windows in c: from your home directory Exercise: 12. Create a directory called IST3020 in My documents folder from your home directory 13. Change directory to IST3020 14. Create a directory in IST3020 called Lab Exercises Exercise: 15. Create the following files in IST3020 folder: • A. DOC • AA. DOC • AAA. DOC • B. DOC • BBB. DOC • A. TXT • BB. TXT • BBBB. TXT 16. Copy all files whose name starts with the letter A and have the extension . oc to the Lab Exercises folder 17. Copy all files whose name starts with the letters BB and whose file name is three characters long to the Lab Exercises folder Exercise: 18. rename BBBB. TXT in IST3020 to BAB. TXT 19. Rename all files that start with extension. doc in Lab Exercises to extension. txt Exercises: • Create a batch file that makes a directory in your current folder (z:) called lesson1. It should then copy all txt files in your current directory to this folder. After that it should change directory to lesson1, display the contents, and then return to the root. Create a batch file to delete all temporary files. Temporary files have the extension . tmp Exercise 1. Create a batch file that takes in the name of a file as an argument then checks and informs the user if the file was found 2. Create a batch file that takes in the name of a file as an argument then checks and deletes the file if the file was found or informs the user that the file was not found Exercise 3. Create a batch file that asks the user for a file to search for and informs the user if the file was found or not.

If the file has been found it should open the file. 4. Create a batch file that copies a file that the user specifies into a back up folder. The batch file should check to find out if such a folder exists. If the folder does not exist it should create one. Exercises: Create a batch file that asks for the name of a file and then displays the contents of that file Exercise • Create a batch file that displays the contents of any file the user keys in as an argument. It should first search for the file and exit if the file

How to cite this assignment

Choose cite format:
Ms Dos Basics Assignment. (2021, Jul 18). Retrieved November 5, 2024, from https://anyassignment.com/samples/ms-dos-basics-8331/