-
-
Save FarisHijazi/8750e7978def3996f793d85272b63b1f to your computer and use it in GitHub Desktop.
@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 | |
) | |
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\"" |
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.
I've tried adding this but unfortunately it never works for me. For my example, I have the script located at D:\Scripts\unzip_and_delete.bat
My script looks as follows:
And my registry values always look like this:
The error I get is as follows:
UPDATE: Right after making this post, I was able to figure it out! I guess I just had to complain about it, but I hope my comment will help someone else in the future. What tipped me off is the grey "S" that was appearing in Notepad++ syntax highlighting, and I was missing another backslash. In my example / setup, this is the correct registry - please use as a reference or adjust as you need. Enjoy and thanks, my apologies for the post and update but I hope this bit of troubleshooting helps someone else in the future!