Last active
January 7, 2025 19:33
-
-
Save FarisHijazi/8750e7978def3996f793d85272b63b1f to your computer and use it in GitHub Desktop.
7zip: Unzip and delete context menu. Registry entry and .bat file for windows context menu "unzip and delete" command. instead of needing to unzip, then delete an archive manually
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set output_dir=%~n1 | |
IF EXIST "%output_dir%\" ( | |
echo "%output_dir%\" already exists, gonna increment the name | |
set "n=0" | |
:loop | |
set /a n+=1 | |
set "output_dir=%output_dir%_%n%" | |
if exist "%output_dir%" echo "%output_dir%" already exists & goto :loop | |
) | |
"C:\Program Files\7-Zip\7z.exe" x %1 -o"%output_dir%\" | |
IF %ERRORLEVEL% EQU 0 IF EXIST "%output_dir%\" ( | |
echo "%output_dir%\" was created | |
del %1 | |
) else ( | |
Echo An error was found & pause | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\*\shell\Unzip and delete] | |
"icon"="C:\\Program Files\\7-Zip\\7zG.exe" | |
[HKEY_CLASSES_ROOT\*\shell\Unzip and delete\command] | |
@="\"<PATH TO>\\unzip_and_delete.bat\" \"%1\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed an unfortunate side effect that I'm not entirely sure if others have encountered, but if you attempt to unzip and delete a file that has an & in the name you'll wind up with a truncated directory nameand Windows will be unable to delete the directory.
Fortunately, you can use 7-Zip itself as a File Manager and it seems to have the ability to allow you to rename the folder, and then you can delete it or use it appropriately.
I'm sure there's probably a way to add some additional logic to prevent or fix this from happening with escaping characters, but hopefully someone smarter than myself will be able to identify what is required to do this.
Just a heads up here and to anyone else that may see this - thank you! At the moment I need to be careful when batch unzip/deleting large amounts of files and identifying if they have a & before processing.