0

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!

adjuzy
  • 511
  • 2
  • 6
  • 22
  • You want to remove `/` from delims for time. And you want `tokens=2,3` as the descriptive label has a colon so token 1 is `The current time is`. –  Mar 23 '16 at 10:53
  • Thanks @Noodles, makes sense. Just need it to extract to its current location now – adjuzy Mar 23 '16 at 11:58
  • `%%~dpf` is the folder containing the zip. See `for /?`. –  Mar 23 '16 at 12:13
  • Wahoo thanks @Noodles! Working as planned now :) – adjuzy Mar 23 '16 at 12:38
  • For code in questions/answers, you can add 4 leading spaces so you don't have to have breaks in-between the lines of code, or worry about the backtick being in the code itself. – Bloodied Mar 23 '16 at 18:14

1 Answers1

0

As @Noodles pointed out in the comments above, %%~dpf is the folder containing the zip.

adjuzy
  • 511
  • 2
  • 6
  • 22