How to Compress or Extract files and folders using CMD?
Last Updated :
30 Aug, 2024
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.
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.
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.
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
Similar Reads
How to Delete a File or Folder Using CMD? When working with files on Windows, File Explorer usually makes creating and deleting files simple. But what if File Explorer freezes or stops responding? In such cases, the Command Prompt (CMD) offers a reliable alternative. CMD allows you to create and delete files or folders using simple commands
4 min read
How to Compress and Extract Files Using the tar Command on Linux Tar archives are special files that bundle multiple files and directories into a single file, making it easier to store, share, and manage. While tar archives themselves are not compressed, they can be combined with various compression utilities to reduce their size. The tar command is highly versat
3 min read
How to Rename Files and Folders Using CMD? Renaming files and folders is a fundamental task for system organization. While it's simple through the graphical interface, using CMD provides more flexibility, particularly for batch operations or when the interface is unavailable.In this guide, youâll master the ren (or rename) command, a built-i
4 min read
How to Copy Files from One Directory to Another Using CMD Have you ever needed to copy a bunch of files from one folder to another without clicking through endless windows? Or perhaps youâre looking to streamline a repetitive task with a single line of text? If so, the Command Prompt (CMD) on Windows is here to save the day! Copying files between directori
5 min read
How to Zip and Unzip Files and Folders on MacOS Facing trouble in sending large files via mail? Well, "File Compression" is the answer to that. File compression reduces the size of files and folders and is effective for memory management, organizing files and much more. In this tutorial, we are going to discuss the best and easiest methods of com
5 min read