I have a small section of a windows batch script that for every zip file it finds, it unzips it to a specific location, then deletes it. This works fine, however I was looking to amend it so when it finds a zip file, it should extract it to a new folder inside its current folder named "current .zip name + current date-time". But I can't seem to get this working, it looks like it extracts it to the parent folder I specify to search instead of the folder where it is found.
The reason for this requirement is that the .zip will be stored in a different folder every time named after the build, e.g. \server\g$\Dashboard\Results\NightlyBuild\25\ so I would want the zip extracted inside this same folder.
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%b-%%a)
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
for /R \\server\g$\Dashboard\Results\NightlyBuild\ %%f in (*.zip) do
"C:\Program Files (x86)\WinZip\WZUNZIP.EXE" -d %%f "%%~nf-%mydate%-%mytime%\"
if ERRORLEVEL 0 for /R \\server\g$\Dashboard\Results\NightlyBuild\ %%f in (*.zip) do del %%f
Any help is greatly appreciated, thanks!
As @Noodles pointed out in the comments above, %%~dpf
is the folder containing the zip.