The expand command is a Command Prompt command used to extract a single file or a group of files from a compressed file.
This command is typically used to replace damaged files in the operating system by extracting working copies of files from the original compressed files on the operating system's CD.
Expand Command Availability
The expand command is available from the Command Prompt in modern versions of Windows, like Windows 11 and Windows 10, as well as from within the Recovery Console in Windows 2000 and XP.
Expand Command Syntax
Use the following syntax for the expand command:
expand source [destination] [/r] [/i] [/d] [/f [:filespec]] [/y]
The availability of certain expand command switches and other command syntax may differ from operating system to operating system. See How to Read Command Syntax if you're not sure how to read the syntax above or in the table below.
Expand Command Options | |
---|---|
Item | Description |
/r | Renames expanded files. |
source | Location of the compressed file. For example, this would be the location of a file on the Windows CD. |
destination | The directory where the source file(s) should be copied to. Can consist of a drive letter and colon, a directory name, a file name, or a combination of these. If source consists of multiple files and you don't specify /r, destination must be a directory. |
/i | Renames expanded files but ignores the directory structure. Applies to Windows Server 2008 R2 and Windows 7. |
/d | Lists the files contained in the source but doesn't extract them. |
/f:filespec | The name of the file that you want to extract from the source file. If the source only contains one file, this option isn't necessary. |
/y | Prevents the command from informing you if you are copying over files in this process. |
Expand Command Examples
Below are a few examples that show how this command can be used.
Extract Hal.dll to System32
expand d:\i386\hal.dl_ c:\windows\system32 /y
In this example, a compressed version of the hal.dll file (hal.dl_) is extracted (as hal.dll) to the c:\windows\system32 directory. The /y option prevents Windows from asking us if we would like to copy over the existing hal.dll file located in the system32 folder, if there happens to be an existing copy there already.
Display What's in a CAB File
expand /d d:\i386\driver.cab
In this example, all the files contained in the compressed file driver.cab are displayed on the screen. No files are actually extracted to the computer.
Related Commands
This command is sometimes used with the dir command, which can list the name of all the files in any given folder, right there in Command Prompt. This is helpful so you know exactly what to type when you use the expand command.