Dos Prompt Home Page Command Prompt
Working with Files and Folders

This page explains how to work with files and folders in a Windows Command Prompt. It is part of our getting started guide for the Command Prompt on Windows.

There are two commands you will use most

  1. "CD" (change directory) (minus quotes). This changes directory relevant to the one you are currently working in.
  2. "DIR" (directory) (minus quotes). This lists the files and directories in the folder that you are in.

DIR

The "Dir" command is probably the most basic command. It gives you a listing of all the files and folders that are located in the folder that you are currently open in.
For example, in the screenshot above, we are in the root of the C:\ drive. If a DIR command is carried out at this point, then you will get a result similar to this:

Volume in drive C is System
Volume Serial Number is 1234-5678

 Directory of C:\

25/10/2002 23:42 0 AUTOEXEC.BAT
26/10/2002 01:03 0 COMLOG.txt
25/10/2002 23:42 0 CONFIG.SYS
06/02/2003 15:08 0 dir.txt
04/11/2002 20:40 262,144 ntuser.dat
25/10/2002 23:49 <DIR> Documents and Settings
27/01/2003 19:58 <DIR> Program Files
27/01/2003 09:26 <DIR> WINDOWS
5 File(s) 262,144 bytes
3 Dir(s) 12,528,111,616 bytes free

This command does not show you any hidden files. To see hidden files you will need to use the ATTRIB command.

Advanced "dir" commands

You can get a little more advanced with the dir command by putting extra commands after the intitial "dir".
For example:

dir /s

will show the contents of the current folder, and any subfolders that are below. This will produce a very long file listing. You might want to filter the results or send them to a text file (see above).

dir /s something.doc

This command will search through all subdirectories below for a file that matches that file name. Similarly, issuing the command

dir /s *.doc

will list all files that end in .doc (Word files).

More information on the DIR command can be found in the DIR Command Reference.

CD - Change Directory

The CD command is very simple to use and  all commands are relative to the directory that you are in. Therefore if you want to change to the "Windows" directory, you would type

CD Windows

If you then wanted to change to the "system" directory (which is a sub directory of "windows"), you would enter

CD System

However if you knew that you wanted to change to the system directory immediately, you could type this command instead:

CD Windows\System

However if you were already deep in another directory (for example c:\ documents and settings) and then wanted to move directly to windows\system then you can do that by putting in an initial backwards slash:

 CD \Windows\System

This tells the command to go to the root of the drive, then to the directory Windows and system.

Moving Back Up

You can also move back up the tree, instead of down.

If you want to just return to the root of the drive (C:\) you would just type

 cd \  or cd\

If you wanted to just go back one level (to use the earlier example, you were in c:\windows\system and you wanted to be in c:\windows) you would just type:

 cd..

Alternatively, if you want to access a totally different directory, for example "Program Files" you could type

cd program files or cd "program files"

When typing directories to change to, if the directory name is unique, then you can use wild cards. For example

cd program*

Directory Entry Shortcut: : If you are on Windows 2000 or XP and you have a Windows Explorer screen open at the location that you want to run a Command Prompt command you could open the Command Prompt and typing a long series of directories or CD commands. Instead, just type CD and then a space, then drag and drop the directory you want to work in to the Command Prompt window. The full path to the directory will be entered, ready for you to press enter.

More information on the CD command can be found in the CD Command Reference.

Change Drive

If you want to run a command against a directory on another drive, such as the D drive, then you need to change to that drive, This is done simply by entering the drive letter and a colon:

d:

On Windows Vista and higher you can also combine the drive letter change and directory by using the full path:

cd d:\downloads

On Windows XP and older, you can still enter the above command, but will then need to do d: . When you do, you will find that you are in the directory where you did the CD command to. 

You can rename files in a command prompt.

rename something.txt someone.txt

would rename the file something.txt to someone.txt

Full Rename Command Reference.

You can create directories from the command prompt:

 mkdir something

would create a directory called "something".
If you want a directory with a name that has a space in it, such as "My Files" you need include the command in " ":

 mkdir "my files"

This ensures that the directory is created with the space. Without the space you will get a new directory called "my" and an error message.

 You can also use the md command instead of mkdir.

If you want to delete a file, then just type:

del filename.ext

If you want to delete all files in a folder then type

del *.*

similarly if you want to delete all files with a certain extension, then type

del *.ext

(where ext is the extension you want to delete)

To delete a folder, simply enter

del foldername

There are more advanced options for deleting files through the Command Prompt - view the Command Reference for DEL to see the full list.

Note - if you delete a file within a Command Prompt session it does not go in to the recycle bin. It will be deleted immediately.

You can purchase books which cover the Command Prompt in more depth from our Amazon Store.

 

 

 

Top of the Page - Home Page
Last Page Update: 29/03/2015

© Sembee Ltd. 1998 - 2016.

Reproduction of any content on this web site is prohibited without express written consent. Use of this web site is subject to our terms and conditions.

All trademarks and registered trademarks are property of their respective owners. This site is not endorsed or recommended by any company or organisation mentioned within and is to provide guidance only and as such we cannot be held responsible for any consequences of following the advice given.

Sembee Ltd. is registered in England and Wales at 1 Carnegie Road, Newbury, Berkshire, RG14 5DJ.
Registered company number: 4704428. VAT Number GB 904 5603 43.

Server 2