Introduction to MS-DOS File System MS-DOS uses a tree like file system. The data are stored in files, and these files are grouped into directories. The directories can have further sub- directories, which in turn can have files and sub-directories and so on. This can be represented as below: c:\ (the root directory) | |---dos | |--- file1 | |--- file8 | |--- flowdata | |--- dir5 | |--file2 <--- 1 | |---tempfile <--- 2 |---system |--- config.sys ...and so on Any file can be accessed by specifying the complete path name and the filename. For example, to print the file pointed to by 1 on the screen, we could say: TYPE c:\dos\dir5\file2 The filename consists of 2 parts: xxxxxxxx.zzz Here xxxxxxxx (maximum of 8 characters) is the actual filename, while zzz (maximum of 3 characters) is the file extension. Wildcard characters (allow to address more than 1 file) '*' refers to a single or multiple characters, '?' refers to only a single character. Hence c:\dos\f* refers to c:\dos\file1, c:\dos\file8, and c:\dos\flowdata. On the other hand, c:\dos\file? refers to c:\dos\file1 and c:\dos\file8 only. Notes: - '[]' means optional parameter. - All DOS commands and parameters are not case-sensitive (i.e., upper-case letters are not distinguished from lower-case letters). CD (change current directory) usage: CD directory_name As the name suggests, the current working directory is changed to the name specified. If '$p' is specified with the PROMPT command, the current directory path can be seen on the DOS prompt line. Common usages include: CD \ (which takes to the root directory), and CD .. (which takes to the parent directory). CLS (clear screen© usage: CLS COPY (to copy a file) usage: COPY [path] source-filename [path] destination-filename For example, to copy a file named 'notes1.txt' located in directory c:\john, to directory a:\doe\harry with a name 'notes5.txt', we could do the following: copy c:\john\notes1.txt a:\doe\harry\notes5.txt However, if we want the name of new file to be same as the original one, the '\notes5.txt' part can be left out (it is defaulted to the original name). If we want to copy all files from directory c:\john to directory a:\doe\harry, we can use the wildcard character '*' : copy c:\john\*.* a:\doe\harry In this case, all the newly copied files have the same names as the original. Note: The use of COPY command does not affect the source files. DEL (to delete a file) usage: DEL [path] filename The named file is deleted. To delete all files, use thå wildcard character '*§ aó in: DEL *.* DIR (display all files and sub-directories) usage: DIR [path] [filename] [/p] [/w] If path is not specified, a list of files and sub-directories of the current directory is shown. Use of /p causes pause between screens. /w displays the listing in wide format. FIND (to search for a specific string in file(s)) usage: FIND [/i] "string" [path] filename The string in quotes is searched for in the file(s) specified. If *.* is given as the filename, all the files in the path are looked into. Use of /i causes a case-insensitive search. MD or MKDIR (create a new directory) usage: MD/MKDIR new-directory-name The new directory created is under the current working directory. Hence if the current directory is c:\dos, and we issue md new, then the tree structure becomes: c:\ | |---dos | |---new | . As a result, the path for files in sub-directory 'new' is c:\dos\new. RD or RMDIR (remove an existing directory) usage: RD/RMDIR directory-name The specified directory is removed. However, it should be empty before the 'rd' command can be issued. RENAME (to rename a file) usage: RENAME [path] old-filename new-filename The old filename is renamed to the new-name specified. However, the new-named file will exist in the same path as the old file. Hence, 'rename' cannot be used to move files from a directory to another. TYPE (to display a file) usage: TYPE [path] filename It should not be used to view binary files (.com, .exe etc). REDIRECTING THE COMMAND INPUT/OUTPUT The following are the various redirection parameters: '>' : sends the output of a command to a file or device '>>' : appends the output of a command at the end of a file '<' : takes the input to a command from a file rather than the keyboard. The major difference between '>' and '>>' is that while '>' erases the existing file and creates a new one, '>>' just appends at the end of that file (without deleting it). Examples: If we just execute: TYPE file.txt ; the contents of the file are displayed on the screen. However, if we do: TYPE file.txt > file2¬ the output is put into the new file - 'file2', rather than displaying it on the screen. This turns out to be exactly the same as COPY command. Now if we do: TYPE file3.txt > file2, the original contents of file2 arå deleted and a new file2 is created having the same contents as file3.txt. However, if we had done: TYPE file3.txt >> file2 the contents of file3.txt would have been appended at the end of the original file2. Suppose our program prog5.exe requires input from the keyboard (use of scanf()). One way is to run it interactively, supplied the values from the keyboard, as and when required. Another way would be: All the input values can be written in a filå - say 'infile' (separated by spaces or tabs or , and in the order they are to be keyed in). And then, we can do: prog5 < infile This will automatically read the input values from 'infile'. And will show the output on the screen. To capture the output in a file named 'outfile', do: prog5 < infile > outfile Hence if prog5.c is the source code file (the C program), compile it into prog5.exe. Then do the following so as to have the C program, input file (prog5.in) and the output, all in a single filå - prog5.out. Type a:\prog5.c > a:\prog5.out Type a:\prog5.in >> a:\prog5.out Type a:\prog5 < a:\prog5.in >> a:\prog5.out Note: Append and redirect the input file only if required.