Store folder name of zip into variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Store folder name of zip into variable

#1 Post by darioit » 25 Feb 2016 07:59

Hello,
I have a zip archive "ZipArchive.7z" which inside this structure:
FolderName\Document1.pdf
FolderName\Document2.pdf

I like to put only "FolderName" into variable.

I wrote this code:

Code: Select all

7za.exe l -r "ZipArchive.7z" | FINDSTR "[0-9].D....\>" | FIND /V "\"


and the result is
2016-02-25 14:33:30 D.... 0 0 FolderName


How can I set DirZipVariable="FolderName"?

Thank you and best regards

Squashman
Expert
Posts: 4484
Joined: 23 Dec 2011 13:59

Re: Store folder name of zip into variable

#2 Post by Squashman » 25 Feb 2016 08:16

Give you a hint. What command do you use to capture the output of another command?
Look back at all the previous questions we have helped you with. You have used it several times.

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: Store folder name of zip into variable

#3 Post by darioit » 25 Feb 2016 09:37

you're alright, sometimes I think difficult solutions for simple things, here the best solutions!

Code: Select all

@echo off
set RESULT=
for /f "delims=" %%a in ('7za.exe l -r "ZipArchive.7z" ^| findstr "[0-9].D....\>" ^| find /v "\"') do set RESULT=%%a
set FName=%RESULT:~53,50%
echo %FName%

Post Reply