Open In App

How to Compress or Extract files and folders using CMD?

Last Updated : 30 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

One effective technique to handle data without depending on third-party software is to use the Command Prompt (CMD) on Windows to compress and extract files and directories. To use CMD to compress files and directories, you must utilize the integrated 7z command-line tool. If you work with large files on your Windows computer, then you need to know how to extract files and folders using the command prompt on Windows. You can manage your documents using the command prompt in just simple steps.

In this article, we will show you how to use basic command prompt commands to compress or extract files and folders. This method also helps in improving the efficiency of file transfer and also saves disk space. Now, follow the below methods step-by-step to Compress or Extract files and folders using CMD.

How to Compress or Extract files and folders using CMD?

Although it is mainly used for NTFS file compression, Windows comes with an integrated application called Compact that allows you to compress files and folders. On the other hand, Windows 10 and later versions of Windows allow you to use the Compact command to create ZIP files. Here are some straightforward ways to compress and extract files and folders using the Command Prompt on Windows, complete with a step-by-step guide.

Method 1: Using Compact Command

Step 1: To compress files Click ‘Win + R', type ‘cmd’ in the open box, and then press Enter.

cmd_3

Step 2: Next, change the directory to the target location using the cd command:

cd C:\Users\YourUsername\Documents

Step 3: After you have navigated to the directory where compression is needed, type the following command to compress a file:

compact /c filename.ext

Replace filename.ext with the name of the file, you want to compress.

image-(2)

To compress an entire folder and its subfolders:

compact /c /s:directoryname

Replace directoryname with the name of the folder you want to compress.

Method 2: Creating a Compressed ZIP File Using Compress Command

Step 1: Open Command Prompt as Administrator.

cmd_4

Step 2: Use the Makecab Command:

First, list all files into a directive file:

dir /b /s *.* > list.txt

Step 3: Then compress the files listed in list.txt:

makecab /f list.txt

How to Extract Files and Folders?

Now, let's check out two different methods on how to extract any file and folder using the command prompt in no time.

Method 1: Using Expand Command

Step 1: Search for Command Prompt by either clicking on the Start menu or pressing Win + R. Type cmd, and then hit the Enter key.

Step 2: Use Expand Command:

Navigate to the location of your compressed file (.cab), Use the cd command to navigate:

cd C:\Path\To\Your\File

from there, you can make use of Expand Command.

expand filename.cab -F:* C:\DestinationFolder

Replace filename.cab with the name of your compressed file and C:\DestinationFolder with the path where you want the files to be extracted.

Method 2: Extracting ZIP Files using PowerShell

Step 1: To launch PowerShell, type that in the Start menu.

Step 2: Use the cd command to navigate to the location of the file:

cd C:\Path\To\Your\File

Step 3: Extract the ZIP file:

Expand-Archive -Path "C:\path\to\your\file.zip" -DestinationPath "C:\path\to\extract\to"

Replace "C:\path\to\your\file.zip" with the path to your ZIP file and "C:\path\to\extract\to" with the path where you want the files to be extracted.

These methods provide you with basic skills for compression and extraction using Command Prompt and PowerShell for files on Windows.

Conclusion

To put it simply, using the Command Prompt in Windows for file/folder compression or deletion is straightforward and efficient. This strategy is particularly valuable for handling large data sets economically. If you learn just a handful of basic commands like ‘’compact” and ”expand’’, you can reduce volumes of disk space and enhance your file organization. Employing these commands consistently will enhance your expertise and enable you to exploit all the capabilities your Windows system offers.

Also Read


Next Article
Article Tags :

Similar Reads