Delete Files After 7-Zip Compression
This guide explains how to automatically remove original source files after creating an archive with 7-Zip. Whether you prefer using the standard Windows graphical interface or automated command-line scripts, 7-Zip includes native options to handle file deletion immediately upon successful compression. Utilizing these settings prevents duplicate data from consuming storage space and eliminates the need for manual file cleanup.
Method 1: Using the 7-Zip Graphical User Interface (GUI)
When working within the Windows desktop environment, you can configure 7-Zip to delete files directly from the archive creation window.
- Select the files or folders you want to compress in File Explorer.
- Right-click the selection, navigate to the 7-Zip context menu, and select Add to archive....
- In the Add to Archive dialog window, locate the Options section on the right-hand side.
- Check the box labeled Delete files after compression.
- Configure your preferred archive format, compression level, and encryption settings as needed.
- Click OK.
7-Zip will compress the selected data. Once the operation finishes without errors, the original source files are automatically removed.
Method 2: Using the 7-Zip Command Line (CLI)
For scripting, automation, or batch processing, the 7-Zip command-line tool provides a dedicated switch to delete source files.
The required switch is: -sdel
Command Syntax:
7z a -sdel <archive_name> <source_files>Example:
To compress a folder named Logs into a .zip
archive and immediately delete the original folder contents:
7z a -sdel "C:\Backups\Logs.zip" "C:\Logs\*"How it works:
a: Adds files to the archive.-sdel: Tells 7-Zip to delete the source files once the archive is written successfully. If the compression process fails or is interrupted, the original files remain intact.
Important Considerations
- Permanent Deletion: Files deleted by 7-Zip (via
both the GUI option and the
-sdelcommand-line switch) are permanently removed from the storage drive and do not go to the Windows Recycle Bin. - Write Permissions: Ensure your user account or script has appropriate write and delete permissions for the source directory; otherwise, the deletion step will fail.