MS-DOS Managing Files, Folders and Directories
In modern versions of Windows opening the command prompt can be achieved by navigating Start > Run and typing CMD and hitting return.
When the MS-DOS command prompt opens, your "logged" path will probably look something like the one below.
C:\Documents and Settings\Administrator>
We're going to want to change that to C:\>. To change your logged path to the root of the current drive use the CD \ command. Your logged path should now be:
C:\>
We're now going to create a new directory called PC-Technician to do this we need to use the make directory command MD.
C:\> MD PC-Technician
Using Windows Explorer check to see that the new folder has been created in the root of your C drive. We're now going to use the DOS Edit program to create a text file in our new directory. Navigate to the new directory first, then type edit.
C:\> CD PC-Technician
C:\PC-Technician>edit
Using the DOS edit program type a few words and save the file in the PC-Technician subfolder as hello.txt. We're now going to view the contents of hello.txt using the Type command.
C:\PC-Technician>type hello.txt
hello!!!
hello!!!
hello!!!
hello!!!
hello!!!
We're now going to create a subfolder within PC-Technician called TextFiles and copy hello.txt to the folder.
C:\PC-Technician>md TextFiles
C:\PC-Technician>tree
Folder PATH listing
Volume serial number is 0000006E 608B:D4C0
C:.
????TextFiles
C:\PC-Technician>cd TextFiles
C:\PC-Technician\TextFiles>copy c:\PC-Technician\hello.txt
1 file(s) copied.
The two new commands introduced here are the Tree command which depending on your logged path displays a graphical representation of the subfolders (and files using /F switch) below the current folder. I used this to check the MD command had created the new subdirectory. I then navigated to the TextFiles subdirectory and used the Copy command to copy the text file into the new folder.
Using Windows Explorer you'll see that because we copied the text file we now have two copies, one in the PC-Technician folder and one in TextFiles. So we're now going to remove the copy we made and move the text file to the TextFiles folder instead.
C:\PC-Technician\TextFiles>del hello.txt
C:\PC-Technician\TextFiles>move c:\PC-Technician\hello.txt
C:\PC-Technician\TextFiles>cd ..
C:\PC-Technician>tree /f
Folder PATH listing
Volume serial number is 0000006E 608B:D4C0
C:.
????TextFiles
hello.txt
Now lets rename the hello.txt file using the ren command.
C:\PC-Technician\TextFiles>ren /?
Renames a file or files.
RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.
Note that you cannot specify a new drive or path for your destination file.
C:\PC-Technician\TextFiles>ren hello.txt goodbye.txt
C:\PC-Technician\TextFiles>cd ..
C:\PC-Technician>tree/f
Folder PATH listing
Volume serial number is 0000006E 3C5D:DA4D
C:.
????TextFiles
goodbye.txt
Ok, to finish the tutorial we'll remove all the files and directories we just created using the delete DEL and remove directory RD commands.
C:\PC-Technician>cd \
C:\>rd PC-Technician
The directory is not empty.
C:\>cd PC-Technician
C:\PC-Technician>cd TextFiles
C:\PC-Technician\TextFiles>del *.*
C:\PC-Technician\TextFiles\*.*, Are you sure (Y/N)? y
C:\PC-Technician\TextFiles>cd ..
C:\PC-Technician>rd TextFiles
C:\PC-Technician>cd \
C:\>rd PC-Technician
The del *.* command is used here to delete all files within a directory. The * wildcard is used twice to match any file with any extension. In this instance we could have used del *.txt or simply del hello.txt to achieve the same result.
The above example showed that the del command will not delete folders that contain files or other folders. There is a command however that will do this. On Windows 2000 and XP you can use the rmdir command with the /s switch, on Previous versions of Windows you can use the deltree command to achieve the same objectives. The following commands were run on a Windows 2000 machine:
C:\>deltree /?
'deltree' is not recognized as an internal or external command,
operable program or batch file.
C:\>rmdir /?
Removes (deletes) a directory.
RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.
/Q Quiet mode, do not ask if ok to remove a directory tree with /S
C:\>rmdir PC-Technician
The directory is not empty.
C:\>rmdir PC-Technician /s
PC-Technician, Are you sure (Y/N)? y
To clear the screen and exit type cls and then exit to close the command prompt.
Note: The commands used in this tutorial won't necessarily be compatible with versions of DOS prior to v7 (Windows 95).

0 Comments:
Post a Comment
<< Home