Jump to content

[SOLVED] Get List File from 7z output list


 Share

Recommended Posts

Hello,
I need help getting the file list in the 7z output list.
Txt data is sort by columns, i have trouble using StringSplit.

So please if you have any help or suggestions.
Thank you.

 

_7z Output

7-Zip (a) 18.03 beta (x86) : Copyright (c) 1999-2018 Igor Pavlov : 2018-03-04

Scanning the drive for archives:
  0M Scan C:\Users\ADMINI~1\AppData\Local\Temp\
                                               
1 file, 24375530 bytes (24 MiB)

Listing archive: C:\Users\ADMINI~1\AppData\Local\Temp\Update-1.05.25-201804212255.7z

--
Path = C:\Users\ADMINI~1\AppData\Local\Temp\Update-1.05.25-201804212255.7z
Type = 7z
Physical Size = 24375530
Headers Size = 525
Method = LZMA2:16 BCJ
Solid = +
Blocks = 4

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2018-04-21 14:44:54 D....            0            0  Data
2018-04-21 14:43:06 D....            0            0  Data\Local
2018-04-21 14:43:46 D....            0            0  Data\Local\Eng
2018-04-21 14:44:37 D....            0            0  Data\Player
2003-01-06 17:35:40 ....A           54      2397240  Data\Dec2.dat
2003-01-06 17:35:32 ....A           54               Data\Enc1.dat
2013-04-10 17:17:58 ....A        28054               Data\Local\Eng\itemsetoption_eng.bmd
2014-12-24 16:18:54 ....A       786264               Data\Local\Eng\Item_eng.bmd
2014-11-10 16:19:42 ....A        72804               Data\Local\Eng\skill_eng.bmd
2015-03-10 16:11:30 ....A       169898               Data\Local\Eng\Text_eng.bmd
2018-04-06 21:18:55 ....A          330               Data\Local\ServerInfo.bmd
2015-07-29 19:38:06 ....A          164               Data\Local\ServerList.bmd
2012-09-03 14:51:04 ....A      3472315               Data\Player\player.bmd
2018-04-20 11:59:11 ....A       128000        47334  IGC.dll
2015-10-04 02:58:22 ....A     35254272     21899657  Main.exe
2017-03-02 16:14:48 ....A        69632        30774  zCustom.dll
------------------- ----- ------------ ------------  ------------------------
2018-04-21 14:44:54           39981841     24375005  12 files, 4 folders

_#

Global $dataOUT = ""
$dataOUT &= '7-Zip (a) 18.03 beta (x86) : Copyright (c) 1999-2018 Igor Pavlov : 2018-03-04' & @CRLF
$dataOUT &= '' & @CRLF
$dataOUT &= 'Scanning the drive for archives:' & @CRLF
$dataOUT &= '  0M Scan C:\Users\ADMINI~1\AppData\Local\Temp\' & @CRLF
$dataOUT &= '                                               ' & @CRLF
$dataOUT &= '1 file, 24375530 bytes (24 MiB)' & @CRLF
$dataOUT &= '' & @CRLF
$dataOUT &= 'Listing archive: C:\Users\ADMINI~1\AppData\Local\Temp\Update-1.05.25-201804212255.7z' & @CRLF
$dataOUT &= '' & @CRLF
$dataOUT &= '--' & @CRLF
$dataOUT &= 'Path = C:\Users\ADMINI~1\AppData\Local\Temp\Update-1.05.25-201804212255.7z' & @CRLF
$dataOUT &= 'Type = 7z' & @CRLF
$dataOUT &= 'Physical Size = 24375530' & @CRLF
$dataOUT &= 'Headers Size = 525' & @CRLF
$dataOUT &= 'Method = LZMA2:16 BCJ' & @CRLF
$dataOUT &= 'Solid = +' & @CRLF
$dataOUT &= 'Blocks = 4' & @CRLF
$dataOUT &= '' & @CRLF
$dataOUT &= '   Date      Time    Attr         Size   Compressed  Name' & @CRLF
$dataOUT &= '------------------- ----- ------------ ------------  ------------------------' & @CRLF
$dataOUT &= '2018-04-21 14:44:54 D....            0            0  Data' & @CRLF
$dataOUT &= '2018-04-21 14:43:06 D....            0            0  Data\Local' & @CRLF
$dataOUT &= '2018-04-21 14:43:46 D....            0            0  Data\Local\Eng' & @CRLF
$dataOUT &= '2018-04-21 14:44:37 D....            0            0  Data\Player' & @CRLF
$dataOUT &= '2003-01-06 17:35:40 ....A           54      2397240  Data\Dec2.dat' & @CRLF
$dataOUT &= '2003-01-06 17:35:32 ....A           54               Data\Enc1.dat' & @CRLF
$dataOUT &= '2013-04-10 17:17:58 ....A        28054               Data\Local\Eng\itemsetoption_eng.bmd' & @CRLF
$dataOUT &= '2014-12-24 16:18:54 ....A       786264               Data\Local\Eng\Item_eng.bmd' & @CRLF
$dataOUT &= '2014-11-10 16:19:42 ....A        72804               Data\Local\Eng\skill_eng.bmd' & @CRLF
$dataOUT &= '2015-03-10 16:11:30 ....A       169898               Data\Local\Eng\Text_eng.bmd' & @CRLF
$dataOUT &= '2018-04-06 21:18:55 ....A          330               Data\Local\ServerInfo.bmd' & @CRLF
$dataOUT &= '2015-07-29 19:38:06 ....A          164               Data\Local\ServerList.bmd' & @CRLF
$dataOUT &= '2012-09-03 14:51:04 ....A      3472315               Data\Player\player.bmd' & @CRLF
$dataOUT &= '2018-04-20 11:59:11 ....A       128000        47334  IGC.dll' & @CRLF
$dataOUT &= '2015-10-04 02:58:22 ....A     35254272     21899657  Main.exe' & @CRLF
$dataOUT &= '2017-03-02 16:14:48 ....A        69632        30774  zCustom.dll' & @CRLF
$dataOUT &= '------------------- ----- ------------ ------------  ------------------------' & @CRLF
$dataOUT &= '2018-04-21 14:44:54           39981841     24375005  12 files, 4 folders' & @CRLF
$dataOUT &= '' & @CRLF

Local $aResult = StringRegExp($dataOUT, "\h*(\d+)\hfiles", 1)
Local $iFiles = $aResult[0]
$aResult = StringRegExp($dataOUT, ",\h*(\d+)\hfolders", 1)
Local $iFolders = $aResult[0]

 

Edited by VIP
[SOLVED]

Regards,
 

Link to comment
Share on other sites

You could try:

#include <Array.au3>
#include <AutoItConstants.au3>

Global $s7Zip = @OSArch = "x64" ? EnvGet("ProgramW6432") & "\7-Zip" : @ProgramFilesDir & "\7-Zip"

Global $a7ZArchiveList = _7ZList("C:\Downloads\FileName.7z")
_ArrayDisplay($a7ZArchiveList, "7-Zip Archive List", "", 0, Default, "Date/Time|Attributes|Size|Compressed|FileName")

Func _7ZList($_sArchivePath)
    Local $sOutput = "", $sError = ""
    Local $iProcessId = Run($s7Zip & '\7z.exe l -r "' & $_sArchivePath & '"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $sOutput &= StdoutRead($iProcessId)
        If @error Then ExitLoop
    WEnd

    While 1
        $sError &= StderrRead($iProcessId)
        If @error Then ExitLoop
    WEnd

    If StringStripWS($sError, 8) <> "" Then Exit MsgBox(4096, "7-Zip Error", $sError)
    Local $bStart = False, $aOutput = StringSplit($sOutput, @CRLF), $a7ZArchive[1][5]
    For $i = $aOutput[0] To 1 Step - 1
        If StringStripWS($aOutput[$i], 8) = "" Then
            _ArrayDelete($aOutput, $i)
            ContinueLoop
        EndIf
        If StringInStr($aOutput[$i],  "------------------- ----- ------------ ------------  ------------------------") Then
            If $bStart = False Then
                $bStart = True
                ContinueLoop
            ElseIf $bStart = True Then
                $bStart = False
                ContinueLoop
            EndIf
        EndIf
        If $bStart Then
            _ArrayAdd($a7ZArchive, _
            StringStripWS(StringMid($aOutput[$i], 1, 19), 7) & "|" & _
            StringStripWS(StringMid($aOutput[$i], 21, 5), 7) & "|" & _
            StringStripWS(StringMid($aOutput[$i], 27, 12), 7) & "|" & _
            StringStripWS(StringMid($aOutput[$i], 40, 12), 7) & "|" & _
            StringStripWS(StringMid($aOutput[$i], 54, StringLen($aOutput[$i]) - 53), 7))
        EndIf
    Next
    _ArraySort($a7ZArchive, 0, 1, 0, 4)
    $a7ZArchive[0][0] = UBound($a7ZArchive) - 1
    Return $a7ZArchive
EndFunc

 

Link to comment
Share on other sites

Thank you for your help.  In the meantime, i have found the solution to work quickly and accurately with 7z Dll

Using

StdoutRead

and

 StderrRead

to read the output takes a lot of time with files with multiple files inside compressed files.

If you run the output command directly to the file is extremely fast. typing command to CMD, it works.

"C:\Program Files\7-Zip\7z.exe\7z.exe" l -r "C:\test 1\file.7z" > "C:\Users\ADMINI~1\AppData\Local\Temp\list-stout.txt"

But I can not run that command success in autoit

#include <Array.au3>
#include <AutoItConstants.au3>

Global $s7zExePath = "C:\Program Files\7-Zip\7z.exe\7z.exe"
Global $s7zListOutPath = @TempDir & "\list-stout.txt"
Global $sArchive= "C:\test 1\1.05.24.7z"

ConsoleWrite("!7Z EXE     :: " & $s7zExePath & " > FileExists:" & FileExists($s7zExePath) & @CRLF)
ConsoleWrite("!7Z List    :: " & $s7zListOutPath & " > FileExists: " & FileExists($s7zListOutPath) & @CRLF)
ConsoleWrite("!7Z Archive :: " & $sArchive & " > FileExists: " & FileExists($sArchive) & @CRLF)

Global $iCommand = '"' & $s7zExePath & '" l -r ' & '"' & $sArchive & '" >' & ' "' & $s7zListOutPath & '"'
ConsoleWrite($iCommand & @CRLF)
Global $iPID = RunWait($iCommand, "", @SW_HIDE)
;~  Globa $iPID = Run($iCommand, "", @SW_HIDE)
ConsoleWrite("!Run PID: " & $iPID & " > Error:" & @error & " > Extended:" & @extended& @CRLF)
;~  ProcessWaitClose($iPID)
Sleep(50)
Global $sConsole = FileRead($s7zListOutPath)
ConsoleWrite("!FileExists: " & FileExists($s7zListOutPath) & @CRLF)
ConsoleWrite("-File Content: " & @CRLF & $sConsole & @CRLF)

 

Regards,
 

Link to comment
Share on other sites

StdOutRead should take the same time as piping it to @TempDir & "\list-stout.txt".  The issue with script above is scraping of text on each line, I tested it on a 9.7GB file with 4313 files and 1498 folders and it took about 3 minutes to complete, removing everything but capturing the file names and using the same 9.7GB file I was able to cut this down to 15 secs using the following:

#include <Array.au3>
#include <AutoItConstants.au3>

Global $s7Zip = @OSArch = "x64" ? EnvGet("ProgramW6432") & "\7-Zip" : @ProgramFilesDir & "\7-Zip"

Global $a7ZArchiveList = _7ZList("C:\test 1\1.05.24.7z", 1)
_ArrayDisplay($a7ZArchiveList, "7-Zip Archive List", "", 0, Default, "Date/Time|Attributes|Size|Compressed|FileName")

Func _7ZList($_sArchivePath, $iFolderFlag = 0) ;~ 0 = Don't Include Folders, 1 = Include Folders
    Local $sOutput = "", $sError = ""
    Local $iProcessId = Run($s7Zip & '\7z.exe l -r "' & $_sArchivePath & '"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
        $sOutput &= StdoutRead($iProcessId)
        If @error Then ExitLoop
    WEnd

    While 1
        $sError &= StderrRead($iProcessId)
        If @error Then ExitLoop
    WEnd
    If $sOutput <> "" Then MsgBox(4096, "7-Zip Archive List", $sOutput)
    If StringStripWS($sError, 8) <> "" Then Exit MsgBox(4096, "7-Zip Error", $sError)
    Local $bStart = False, $aOutput = StringSplit($sOutput, @CRLF), $a7ZArchive[1]
    For $i = $aOutput[0] To 1 Step - 1
        If StringStripWS($aOutput[$i], 8) = "" Then ContinueLoop
        If StringInStr($aOutput[$i],  "------------------- ----- ------------ ------------  ------------------------") Then
            If $bStart = False Then
                $bStart = True
                ContinueLoop
            ElseIf $bStart = True Then
                $bStart = False
                ContinueLoop
            EndIf
        EndIf
        If $bStart Then
            If  $iFolderFlag = 0 And StringInStr(StringStripWS(StringMid($aOutput[$i], 21, 5), 7), "D") Then ContinueLoop
            _ArrayAdd($a7ZArchive, StringStripWS(StringMid($aOutput[$i], 54, StringLen($aOutput[$i]) - 53), 7))
        EndIf
    Next
    _ArraySort($a7ZArchive)
    $a7ZArchive[0] = UBound($a7ZArchive) - 1
    Return $a7ZArchive
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...