Home : Free Tutorials : Other : DOS
DOS Basics:

Directory structure and commands: navigating and working with folders in DOS

Before the existence of point and click graphic operating systems, PC’s were controlled by typing commands at a flashing prompt, within a text-based “command line” environment called DOS (“daas”). Microsoft Windows replaced Microsoft DOS as an operating environment because it provided more intuitive menu/icon selections using a graphic interface. Even though computers are now made to do most of their work within a graphic environment, command line controls still have a place. You will find that it’s necessary to use DOS commands when installing Windows or troubleshooting certain software problems, and you may find that DOS commands provide helpful shortcuts to completing tasks, even when working in Windows.

DOS stands for “Disk Operating System”, and a significant number of its modern commands still pertain to reading, writing, and manipulating data files on the hard drive and other disks inside the computer. Data on your hard drive is organized into a tree of hierarchical folders, each containing individual files and additional branches of nested folders. The root directory of your drive is called “C:\”. C: is the letter name given to your main hard disk, and “\” (“backslash”) represents the main directory (i.e., the base/top folder) of the directory tree. At the DOS command line, you are prompted by a flashing cursor, next to a prompt that tells you which file folder you are currently working with on the hard drive.

To get a DOS prompt when starting your computer, you can press the [F8] key repeatedly, until the Windows start menu appears. Select “Command Prompt Only” to run the computer using a traditional text based DOS command line. You can also get a similar prompt by inserting the Windows “Boot Disk” (the emergency startup disk that comes with Microsoft Windows) into the floppy drive before turning the computer on. To get to a DOS prompt in Windows, where you can enter the same commands, click START -> RUN -> type “command” (without the quotes) -> click OK. A small window will appear with a blinking cursor, next to a prompt similar to the following:

C:\Windows\Desktop>_

The above prompt tells the user that he/she is currently working with the contents of the C: drive, inside a folder called “desktop”, which is found on the hard drive, inside another folder called “windows”.

-------------- C: ---------------------

| |

-------- WINDOWS

| | |

(etc) (etc) -------- DESKTOP (you are here)------------

| | |

(My Computer) (My Documents) (etc.)

Moving around between the folders of the hard drive is accomplished with the “CD” (“change directory”) command. To enter a command in DOS, type the name of the command, followed by a space, followed any required parameters (option controls), followed by the [ENTER] key (sometimes called “[RETURN]” ). DOS commands are not case sensitive, meaning it doesn’t matter if you type them in lower or uppercase.

Try typing the following:

CD \ [ENTER]

You will see your prompt change to the following:

C:\>

Now type:

DIR [ENTER]

You will see a flurry of folder and filenames pass upwards quickly across your screen. This is the contents of your C: drive root directory - several files of which allow your computer to start, so be sure to TYPE CAREFULLY from this point on!

(pic)

Now type the following (be prepared to wait for a bit after that second command, as the files fly by):

CD \WINDOWS [ENTER]

DIR [ENTER]

What you just did was to switch (cd) to the “Windows” directory of the hard drive, and view the list (dir) of files in that folder. Note that the DIR command differentiates between individual files, and other nested folders by displaying the word next to folder names in the list.

To view the listing in a more readable fashion, try typing the following:

DIR /P [ENTER]

The “/P” (“forward slash P”) switch is an optional parameter that only displays one Page of the directory listing at a time. Press the [ENTER] key, or any other key (as it says) to look at the entire list of files in your Windows folder, one page at a time. When you get tired of looking, press the [CTRL] + [C] keys together (hold down both keys at the same time). This key combination is used to end any currently running DOS command.

You can create new folders within your current folder by typing “MD” (“make directory”), followed by a space, followed by the name of the new folder (up to 8 characters in traditional DOS longer folder names are allowed in Windows) ... and BE CAREFUL to type correctly!!!

MD MYNEWDIR [ENTER]

If you do a “dir” command next (DIR [ENTER]), you will see that the folder “mynewdir” has been created as a subdirectory of “windows”, and is now at the end of the dir listing in C:\Windows.

Now try changing into that new directory:

CD MYNEWDIR [ENTER]

Then look at the contents::

DIR [ENTER]

You will see that the directory listing is empty, except for two folders labeled “.” and “..” (one dot, and two dots). The one dot (period) represents the current directory in which DOS commands are being executed (i.e., in this case C:\WINDOWS\MYNEWDIR). The double dot represents the “parent” directory of the current working directory or, the folder which contains the directory you are currently using (in this case “..” = C:\WINDOWS.)

Try typing the following command now:

CD ..

You will see that your prompt is changed back to “C:\WINDOWS.” To DOS, the above command means “switch up one directory, to the parent folder containing the folder I’m working in now”.

Type the above command again:

CD ..

Now you are moved into the C:\ directory (root folder) of the hard disk the one that contained the previous folder C:\WINDOWS.

To switch back to a directory nested within another folder (as in the case of the mynewdir folder we just created), you need to type the full “path” (location in the directory tree) of the folder you want. The path includes the drive name, followed by each of the containing folders, starting with the root. In the case of the folder we created above, you can switch to it from any location on the hard drive by typing:

CD C:\WINDOWS\MYNEWDIR [ENTER]

If you try to switch to a folder that is not a subdirectory of your current folder (i.e., not contained in the current folder), you will get the response “Invalid Directory”. Try switching to C:\WINDOWS from your current location. You will get an error because C:\Windows is the parent directory of our current folder not one which is contained in the current folder. You can only switch to subfolders of the current directory by typing “CD+(directory name)”. To switch to any other folder, you need to use the full path name to locate your intended folder. To switch to the Windows directory, you can always type:

CD C:\WINDOWS

Go ahead and type the above command, and then type:

RD MYNEWDIR

“RD” (“remove directory”) is used to delete unused directories in DOS. If you try to switch to a folder which has been deleted, you will get the error “Bad command or file name”. Try switching to the directory you just deleted, for example:

CD C:\WINDOWS\MYNEWDIR [ENTER]

If a folder contains any files whatsoever, you will not be allowed to delete that folder (we will cover file operations such as copying and deleting in the second “DOS Basics” tutorial coming next).

Windows VS. DOS:

Below is a list of folder handling operations as performed in Windows, associated with their analogous commands in DOS. DO NOT perform any of the delete routines in Windows unless you truly intend to delete the folder contents. Windows will not stop you from deleting folders just because they are full.

To perform folder manipulations in Windows, you can use “Windows Explorer”: START -> RUN -> type “explorer” (without the quotes) -> click OK.

Directories appear as yellow folders in the Windows file explorer. You can perform the following routines in Windows to achieve the same results in DOS:

1. In Windows: Double click to open a folder in Windows, or select (highlight) a folder with the mouse and click FILE -> OPEN in the menu above. In DOS: Type “CD + (folder path and name) + [ENTER]”

2. In Windows: Right click a folder (select it with the right mouse button) and select “Delete”, or highlight and select FILE -> DELETE. In DOS: “RD + (folder name) + [ENTER]”

3. In Windows: Create a new subfolder by selecting the parent directory, select FILE -> NEW -> FOLDER, type the name of the folder. In DOS: CD to the parent directory, then type “MD + (folder name) + [ENTER]”

8 + 3 character filenames:

Filenames in traditional DOS were limited to a format of up to 8 characters, followed by a dot, followed by up to 3 additional characters (called the “extention”): xxxxxxxx.xxx. Related file and data types generally have the same 3 character extension. “.mp3” files, for example, are generally music files, and “.doc” files typically represent documents created by a word processor. Windows allows for large strings of characters and spaces that are not allowed in older versions of DOS. “Long filenames” in Windows (larger than xxxxxxxx.xxx), are renamed by DOS using the following conventions:

1)All names are shortened to fit the 8+3 format.

2)Extensions are truncated to 3 characters.

3)Spaces are removed.

4)If the long filename is greater than 8 characters to the left of the dot, the first 8 characters of the filename are laid out as follows: beginning characters of the long filename + “~” (the “tilde” character top left hand corner of the keyboard) + a sequential number.

longfile.abcdefg becomes longfile.abc

long file.abc becomes longfile.abc

longfilename.abc becomes longfi~1.abc

To see how this works in DOS, type:

CD C:\MYDOCU~1 [ENTER]

(This switches you to your “My Documents” folder in Windows, shortened at the command prompt to fit DOS lingo)

DIR [ENTER]

If you have any files in your Windows “My Documents” folder that don’t fit into the 8.3 convention, you will see that they have been appropriately renamed (not changed, just displayed differently) at the DOS prompt.

Copyright © 2004-2009 Nick Antonaccio. All rights reserved.