I have a bunch of zipped files (.rar , .zip) spread out in multiple sub folders but all in the same base folder (F:\1).

I was wondering if there was a way to unzip each file while still retaining its original name (zipped file.zip would turn into F:\1\zipped file).

And if possible delete the original zip file just keeping the unzipped folder.

Is there a way to do this with a batch file so i don't have to do each folder at a time?

Thanks guys :)


your qestion is quite ambigous. An archive usually contains more than one file and may have subfolders included. If you want to create a folder with the same name as the archive (without extension) and store all archive content in there this is a starting point.

:: Expand-Archive.cmd :::::::::::::::::::::::::::::::::::::::::::::::::::::
@Echo off&SetLocal EnableExtensions
Set Base=F:\1
if exist "%~1" Set "Base=%~f1"
Pushd %Base% ||(Echo Can't cd to base folder %base% &Pause&Exit)
For /f "delims=" %%A in ('Dir /B/S/A-D *.zip *.rar') Do Call :Expand "%%A"
Goto :Eof

Set "_Folder=%~dp1"
PushD "%_Folder%"
Set "_Archive=%~nx1"
Set "_NewSubFolder=%~dpn1"
:: Your own code to expand the Archive goes here.
:: I don't know what tool (7zip Infozip etc.) you usually use.
:: with 7z somewhere in your path this might work,
:: remove Echo in the following 2 Lines.
Echo MkDir  "%_NewSubFolder%"
Echo 7z x -O"%_NewSubFolder%" "%_Archive%" && Del "%_Archive%"
Goto :Eof
:: Expand-Archive.cmd :::::::::::::::::::::::::::::::::::::::::::::::::::::


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.