You'll need to install 7-Zip and include the executable somewhere in your PATH, or update this script to explicitly point to your 7-Zip executable.
@echo off
:FILENAME_PARSING
REM Get the base filename (without extension) and the extension (with the period).
for /f "tokens=* delims= " %%F in ('echo %1') do (
set base=%%~nF
set ext=%%~xF
)
:MKDIR
REM Create a new dir to hold the ZIP file and the ZIP contents
mkdir "%base% folder"
move %1 "%base% folder"
cd "%base% folder"
:UNZIP
REM Unzip the file and then delete the ZIP file.
7za x "%base%%ext%" && del "%base%%ext%"
if %ERRORLEVEL% EQU 0 goto COUNT
:UNZIP_ERROR_CLEANUP
REM Something went wrong with the unzip.
REM Move the ZIP file up a level, remove any other files in this dir,
REM then remove this dir.
move "%base%%ext%" ..
del/q *
cd ..
rmdir "%base% folder"
goto END
:COUNT
REM Check if there is exactly one file in this dir.
ls -1 | wc -l | findstr "\<1$" > nul
IF %ERRORLEVEL% EQU 1 goto END
:SOLO_CLEANUP
REM Move the file up a level and then remove this dir.
move * ..
cd ..
rmdir "%base% folder"
:END
pause
No comments:
Post a Comment