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 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-
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 Extract and Copy Files from ISO Image in Linux?
The term ISO was derived from the ISO 9660 file system, which is commonly used by optical media. An ISO image is a full copy of everything contained on a physical optical disc, such as a CD, DVD, or Blu-ray disc, including the file system. There is no compression and they are a sector-by-sector copy
3 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
How to List all Files in a Directory using CMD
Struggling to find or organize files buried in folders on your Windows PC? While File Explorer offers a visual way to browse, the Command Prompt (CMD) provides a faster, more powerful method to list, sort, and manage files, especially when dealing with large directories or automating tasks. In this
5 min read
How to Create a File in CMD
We all know that one can easily create files using GUI options, but what if you can use a faster way to create files through the command-line interface? This is not a necessary but useful skill for anyone working with Windows. Whether you're automating tasks, working on scripts, or preferring using
5 min read
How to Search Files using CMD?
Ever lost a file on your computer and wished there was a quick way to find it without clicking through endless folders? Say hello to the Windows Command Prompt (CMD) a powerful little tool that can help you search for files fast. In this how-to blog, we will explore the steps to search for files usi
5 min read
Copy all files from one directory to another using Python
Copying files from one directory to another involves creating duplicates of files and transferring them from one folder to another. This is helpful when organizing files, backing them up, or moving them to different locations on your computer. Letâs explore various methods to do this efficiently. Us
2 min read
Python - Move and overwrite files and folders
In this article, we will be learning on moving a collection of files and folders where there may be files/folders with the same name as in the source name in the destination. So that we may need to overwrite the existing destination file with the source file. The shutil.move() method is used to move
3 min read