Page 1 of 1

How can get uncompress size 7zip file without extract

Posted: Fri Jun 21, 2024 2:40 pm
by hoangdiemtinh
I am new to PB. My primary language is not US/UK. I am using Google Translate.

I use the "L" switch command (7za.exe), the output has 6 columns: Date, Time, Attr, Size, Compressed, Name.
In the Size column, the bottom content, there is the total uncompress size number.
How to filter out this number ? (ex, in this case: 2087335190)

Code: Select all

Path = E:\my-doc.7z
Type = 7z
Physical Size = 637091330
Headers Size = 354
Method = LZMA2:25 7zAES
Solid = +
Blocks = 1

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2022-05-09 15:22:35 ....A      4197888    637090976  abcd.pdf
2022-03-28 20:08:26 ....A         4815               a1.doc
2024-03-01 12:36:35 ....A        10823               b1.txt
2024-04-09 08:48:24 ....A   2028448768               c1.mp4
2023-07-13 13:54:22 ....A     54672896               d1.mp4
------------------- ----- ------------ ------------  ------------------------
2024-04-09 08:48:24         2087335190    637090976  5 files

Re: How can get uncompress size 7zip file without extract

Posted: Fri Jun 21, 2024 4:06 pm
by Marc56us
Hi,

Assuming that the result of the report is already in a file, you can do something like this:

Code: Select all

If Not OpenFile(0, "7zip.txt") : Debug "No file" : End : EndIf

While Not Eof(0)
    Tmp$ = ReadString(0)
Wend
CloseFile(0)

Size = Val( Mid( Tmp$, 27, 12 ) )

Debug "Full size : " + Size
Debug "Readable  : " + FormatNumber(Size, 0)
Sample result:

Code: Select all

Full size : 2087335190
Readable  : 2,087,335,190
:wink:

Re: How can get uncompress size 7zip file without extract

Posted: Sat Jun 22, 2024 6:31 am
by boddhi

Code: Select all

EnableExplicit
;
#EXE7ZA="" ; 7za or 7z path and file name
#FILETOSCAN=""
CompilerIf #EXE7ZA="" Or #FILETOSCAN=""
  CompilerWarning "All constants must be assigned!"
  End
CompilerEndIf
;
Procedure.i Fc_GetTotalUncompressedSize(ArgFileName.s,ArgExtensions.s="")
  Protected.i Exe7za,Result
  Protected.s Parameters="l -bb3 -sccUTF-8 -scsUTF-8 "+Chr(34)+ArgFileName+Chr(34)+" "+ArgExtensions
  Protected.s OutputString
  Protected.a SepCount
  
  Exe7za=RunProgram(#EXE7ZA,Parameters,"",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read|#PB_Program_Error)
  If Exe7za
    While ProgramRunning(Exe7za)
      If AvailableProgramOutput(Exe7za)
        OutputString=ReadProgramString(Exe7za)
        If SepCount<2 And Left(OutputString,16)="----------------"
          SepCount+1
        ElseIf SepCount=2
          Result=Val(Mid(OutputString,27,12))
          SepCount+1
        EndIf
      EndIf
    Wend
    Select ProgramExitCode(Exe7za)
      Case 0 ; All is OK
      Default  
        ; Case 1: One or several non-fatal errors
        ; Case 2: Fatal error
        ; Case 7: Command line error
        ; Case 8: Insufficient memory
        ; Case 255: Process stopped by user
        Result=-1
    EndSelect
    CloseProgram(Exe7za)
  Else
    Result=-1
  EndIf
  ProcedureReturn Result
EndProcedure

Debug Fc_GetTotalUncompressedSize(#FILETOSCAN)

Re: How can get uncompress size 7zip file without extract

Posted: Sat Jun 22, 2024 1:57 pm
by hoangdiemtinh
@Marc56US @boddhi Thank for your sharing !

All working so great.

Re: How can get uncompress size 7zip file without extract

Posted: Sat Jun 22, 2024 4:37 pm
by Marc56us
Hi,

You know: PB can query, create, extract 7z archive too :D
Query (without extract) total of uncompressed files in 7z archive

Code: Select all

UseLZMAPacker()
Archive$ = "Test.7z"
If Not OpenPack(0, Archive$) : Debug "error" : End : EndIf
If Not ExaminePack(0) : Debug "Bad archive" : End: EndIf

While NextPackEntry(0)
    Size = PackEntrySize(0, #PB_Packer_UncompressedSize)
    Debug "Name: " + LSet(PackEntryName(0), 50, " ") + 
          "Size: " + Size
    FullSize + Size
Wend      
ClosePack(0)
    
Debug #CRLF$ + "Full size of files in archive : " + FullSize + 
      " (" + FormatNumber(FullSize, 0) + ")"
:wink:

Re: How can get uncompress size 7zip file without extract

Posted: Sat Jun 22, 2024 5:54 pm
by hoangdiemtinh
Not support 7z archive which have password