0

I am using 7zip command line in a batch file to extract zip files to folders of the same name as the zip file and output the folders to a destination directory: I've tried a few variations without success including

7za x "%directory_destination%*.zip" -o%directory_destination%\%date%*"

7za x "%directory_destination%\*.zip" -o%directory_destination%\*"

I am having trouble including the current %date% and %time% in the folder name of the extracted zip file.

For example, the contents of a zip file called abc.zip should be extracted to a folder called abc_18.10.14_7.34 etc.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
georgemackenzie
  • 171
  • 2
  • 4
  • 19
  • %date% isnt in your code so no wonder it isnt working, please provide your current working command line. – Toby Allen Oct 18 '14 at 09:00
  • Hi toby I've tried a few variations without success including 7za x "%directory_destination%\*.zip" -o%directory_destination%\%date%*" Im just not sure how to format date and time with the folder names. – georgemackenzie Oct 18 '14 at 09:05
  • This stackoverflow answer may help http://stackoverflow.com/a/865568/6244 – Toby Allen Oct 18 '14 at 09:07
  • Hi Toby sorry this did not help! Any further guidance would be most appreciated :-) – georgemackenzie Oct 18 '14 at 09:25
  • Hi user3785396 you need to supply more information – Toby Allen Oct 18 '14 at 09:30
  • Hi Toby I understand how to format date / time variables as I use them in batch files (see below) but I don’t understand how to apply it to: 7za x "%directory_destination%\*.zip" -o%directory_destination%\*" Date / Time Variables: rem set month=%date:~7,2% rem set yearlong=%date:~-4% rem set hour=%time:~0,2% rem set minute=%time:~3,2% rem set second=%time:~6,2% rem %yearlong%.%month% %hour%.%minute%.%second% – georgemackenzie Oct 18 '14 at 09:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63273/discussion-between-user3785396-and-toby-allen). – georgemackenzie Oct 18 '14 at 09:58
  • I don't want to chat I want you to write a question that can be answered. Put the information you have given me in your question. If you make your question answerable someone will answer it. – Toby Allen Oct 18 '14 at 10:01
  • Hi Toby. I didn't mean to click the chat option. I clicked it by mistake. – georgemackenzie Oct 18 '14 at 10:06

1 Answers1

0

Test this on some sample files:

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

cd /d "c:\folder with zip files\"
set "directory_destination=c:\target\folder"
for /f "delims=" %%a in ('dir *.zip /b /a-d ') do (
   md "%directory_destination%\%%~na_%dd%.%mm%.%yyyy%_%hh%.%min%%%~xa" 2>nul
   7za x "%%a" -o"%directory_destination%\%%~na_%dd%.%mm%.%yyyy%_%hh%.%min%%%~xa"
)
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68