Reading The Contents Without Opening The Zip File Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Reading The Contents Without Opening The Zip File

08 Aug 2019, 04:23

I have documents that are in fact the Zip file which has the format udf. I want to assign the contents of the xml files to the variable. But unzip the zip file and then the contents of the xml file
reading is getting slower. How can I read the xml file directly in the zip.

I couldn't add the Udf extension to the site, so I put it in the zip file.
Sample File Included.zip
(6.53 KiB) Downloaded 72 times
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 04:27

Code: Select all

yol := gst()

IfEqual,yol,
{
	yol=
	return
}
	StringRight,uzanti,yol,3
	IfNotEqual,uzanti,udf
	{
		yol=
		return
	}


FileCreateDir,%A_MyDocuments%\UyapPre
FileDelete,%A_MyDocuments%\UyapPre\*
FileCopy,%yol%,%A_MyDocuments%\UyapPre\Onizleme.zip



kaynak = %A_MyDocuments%\UyapPre\Onizleme.zip
hedef = %A_MyDocuments%\UyapPre
;MsgBox, %kaynak% %hedef%

Unzip(kaynak,hedef)


xlmDosyasi = %A_MyDocuments%\UyapPre\content.xml
okuma := FileOpen(xlmDosyasi, "rw", "UTF-8")

sonuc := okuma.Read(2000)



okuma := FileOpen(xlmDosyasi, "h", "UTF-8")


; comment the next line if you want to see x,y as window relative coords


StringSplit, splitEt, yol, `\
Loop, %splitEt0%
{
	ayrilanMetin := splitEt%A_Index%
}

MsgBox,,%ayrilanMetin%,%sonuc%,8
return

F5::
ToolTip
return

gst() {   ; GetSelectedText or FilePath in Windows Explorer  by Learning one 
	IsClipEmpty := (Clipboard = "") ? 1 : 0
	if !IsClipEmpty {
		ClipboardBackup := ClipboardAll
		While !(Clipboard = "") {
			Clipboard =
			Sleep, 10
		}
	}
	Send, ^c
	ClipWait, 0.1
	ToReturn := Clipboard, Clipboard := ClipboardBackup
	if !IsClipEmpty
	ClipWait, 0.5, 1
	Return ToReturn
}

Unzip(Sources, OutDir, SeparateFolders := false)
{
	Static vOptions := 16|256
	
	Sources := StrReplace(Sources, "`n", ";")
	Sources := StrReplace(Sources, ",", ";")
	Sources := Trim(Sources, ";")
	OutDir := RTrim(OutDir, "\")
	
	objShell := ComObjCreate("Shell.Application")
	Loop, Parse, Sources, `;, %A_Space%%A_Tab%
	{
		objSource := objShell.NameSpace(A_LoopField).Items()
		TargetDir := OutDir
		If (SeparateFolders)
		{
			SplitPath, A_LoopField,,,, FileNameNoExt
			TargetDir .= "\" FileNameNoExt
			If (!InStr(FileExist(TargetDir), "D"))
				FileCreateDir, %TargetDir%
		}
		objTarget := objShell.NameSpace(TargetDir)
		objTarget.CopyHere(objSource, vOptions)
	}
	ObjRelease(objShell)
}
if there is an udf file selected, have such a case study that works by pressing the middle mouse button.
Attachments
ScreeenShot.PNG
ScreeenShot.PNG (116.56 KiB) Viewed 3571 times
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File  Topic is solved

08 Aug 2019, 09:24

Response after your PM:

With the standalone 7za tool, you can print the data to stdout for a specific file.
Say you have a zip files_example.zip with:

Test1.txt
Testfile2.xml
MyAmazingDrawing_01.bmp


And you wanted just the data from Testfile2.xml, you can do the following:

Code: Select all

data := RunWaitOne("7za.exe e -so files_example.zip Testfile2.xml")
MsgBox % data

; Copied function from https://www.autohotkey.com/docs/commands/Run.htm#Examples
RunWaitOne(command) {
    ; WshShell object: http://msdn.microsoft.com/en-us/library/aew9yb99
    shell := ComObjCreate("WScript.Shell")
    ; Execute a single command via cmd.exe
    exec := shell.Exec(ComSpec " /C " command)
    ; Read and return the command's output
    return exec.StdOut.ReadAll()
}
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 15:14

joedf wrote:
08 Aug 2019, 09:24
Response after your PM:

With the standalone 7za tool, you can print the data to stdout for a specific file.
Say you have a zip files_example.zip with:

Test1.txt
Testfile2.xml
MyAmazingDrawing_01.bmp


And you wanted just the data from Testfile2.xml, you can do the following:

Code: Select all

data := RunWaitOne("7za.exe e -so files_example.zip Testfile2.xml")
MsgBox % data

; Copied function from https://www.autohotkey.com/docs/commands/Run.htm#Examples
RunWaitOne(command) {
    ; WshShell object: http://msdn.microsoft.com/en-us/library/aew9yb99
    shell := ComObjCreate("WScript.Shell")
    ; Execute a single command via cmd.exe
    exec := shell.Exec(ComSpec " /C " command)
    ; Read and return the command's output
    return exec.StdOut.ReadAll()
}

Thank you it works great.
There is only one boredom. When you read thousands of files with the loop, the cmd screen comes and goes. can't I hide cmd screens?

Edit: Bu sorun çözüldü. Lexikosun eski forumda paylaştığı bir çözüm.

Code: Select all

DllCall("AllocConsole")
WinHide % "ahk_id " DllCall("GetConsoleWindow", "ptr")
Last edited by hasantr on 08 Aug 2019, 15:44, edited 1 time in total.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 15:43

It does not read as UTF-8. So the characters are not legible. Can StdOut read as utf-8?
Thank you very much indeed. Thanks to you, I can do great things, and I'm motivated to learn more. Thank you.thank you.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 15:44

There's probably a better way to loop through the things you need to do, but you could try just replacing " /C " with " /Q /C ".
The quite or Echo off option for cmd.

For utf8, it might be better to just extract the files to a temporary folder.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 16:00

joedf wrote:
08 Aug 2019, 15:44
There's probably a better way to loop through the things you need to do, but you could try just replacing " /C " with " /Q /C ".
The quite or Echo off option for cmd.

For utf8, it might be better to just extract the files to a temporary folder.
Thank you. Cmd is no longer a problem, I guess.
But the necessity of UTF-8 disappointed me.
Could that be the solution? I didn't really understand what they were doing.
https://www.autohotkey.com/boards/viewtopic.php?f=5&t=6678

Apart from that, I need a formula to clean the teapot that I forgot on the stove before my wife wakes up. The bad part of AHK. :)
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 16:04

joedf If I take too much time, that 's enough for me. Thanks. I don't want to steal any more of your time.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 16:08

I guess you could do what Lexikos suggested at the end of that thread. Here is a modified version:
All I did is replace "CP850" with "UTF-8". So change RunWaitOne with StdOutToVar

Code: Select all

StdOutToVar( sCmd ) { ;  GAHK32 ; Modified Version : SKAN 05-Jul-2013  http://goo.gl/j8XJXY                             
  Static StrGet := "StrGet"     ; Original Author  : Sean 20-Feb-2007  http://goo.gl/mxCdn  
   
  DllCall( "CreatePipe", UIntP,hPipeRead, UIntP,hPipeWrite, UInt,0, UInt,0 )
  DllCall( "SetHandleInformation", UInt,hPipeWrite, UInt,1, UInt,1 )

  VarSetCapacity( STARTUPINFO, 68, 0  )      ; STARTUPINFO          ;  http://goo.gl/fZf24
  NumPut( 68,         STARTUPINFO,  0 )      ; cbSize
  NumPut( 0x100,      STARTUPINFO, 44 )      ; dwFlags    =>  STARTF_USESTDHANDLES = 0x100 
  NumPut( hPipeWrite, STARTUPINFO, 60 )      ; hStdOutput
  NumPut( hPipeWrite, STARTUPINFO, 64 )      ; hStdError

  VarSetCapacity( PROCESS_INFORMATION, 16 )  ; PROCESS_INFORMATION  ;  http://goo.gl/b9BaI      
  
  If ! DllCall( "CreateProcess", UInt,0, UInt,&sCmd, UInt,0, UInt,0 ;  http://goo.gl/USC5a
              , UInt,1, UInt,0x08000000, UInt,0, UInt,0
              , UInt,&STARTUPINFO, UInt,&PROCESS_INFORMATION ) 
   Return "" 
   , DllCall( "CloseHandle", UInt,hPipeWrite ) 
   , DllCall( "CloseHandle", UInt,hPipeRead )
   , DllCall( "SetLastError", Int,-1 )     

  hProcess := NumGet( PROCESS_INFORMATION, 0 )                 
  hThread  := NumGet( PROCESS_INFORMATION, 4 )                      

  DllCall( "CloseHandle", UInt,hPipeWrite )

  AIC := ( SubStr( A_AhkVersion, 1, 3 ) = "1.0" )                   ;  A_IsClassic 
  VarSetCapacity( Buffer, 4096, 0 ), nSz := 0 
  
  While DllCall( "ReadFile", UInt,hPipeRead, UInt,&Buffer, UInt,4094, UIntP,nSz, UInt,0 )
   sOutput .= ( AIC && NumPut( 0, Buffer, nSz, "UChar" ) && VarSetCapacity( Buffer,-1 ) ) 
              ? Buffer : %StrGet%( &Buffer, nSz, "UTF-8" )
 
  DllCall( "GetExitCodeProcess", UInt,hProcess, UIntP,ExitCode )
  DllCall( "CloseHandle", UInt,hProcess  )
  DllCall( "CloseHandle", UInt,hThread   )
  DllCall( "CloseHandle", UInt,hPipeRead )

Return sOutput,  DllCall( "SetLastError", UInt,ExitCode )
}
EDIT:
hasantr wrote:
08 Aug 2019, 16:04
joedf If I take too much time, that 's enough for me. Thanks. I don't want to steal any more of your time.
No worries :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

08 Aug 2019, 17:24

Great, everything works now. Thank you so much.
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

15 Aug 2019, 02:15

joedf wrote:
08 Aug 2019, 22:22
Glad to hear it. :+1:
does not work on files within the intranet. Can an easy solution be found?
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File

15 Aug 2019, 10:10

Errr... I need more context? Any example file paths, etc.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

16 Aug 2019, 03:35

joedf wrote:
15 Aug 2019, 10:10
Errr... I need more context? Any example file paths, etc.
This way. I don't know how to give a different example. I also failed to get a different error.
\\halkali1\ISTHUKUK\sample.zip
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File

16 Aug 2019, 07:41

Hmmm... :think:
You sure, you're not missing something else?
I just tested a networked path like so
C:\Users\Frost\Desktop>7za e -so \\NetworkDrive01\Path\To\Some\File.7z ArchivedFile.txt

If you test it manually in command prompt, and send me the 7za error. Maybe I can see what the problem is?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

16 Aug 2019, 08:17

joedf wrote:
16 Aug 2019, 07:41
Hmmm... :think:
You sure, you're not missing something else?
I just tested a networked path like so
C:\Users\Frost\Desktop>7za e -so \\NetworkDrive01\Path\To\Some\File.7z ArchivedFile.txt

If you test it manually in command prompt, and send me the 7za error. Maybe I can see what the problem is?
That's the end of it. Thank you so much. :D

Code: Select all

data := StdOutToVar("7za.exe e -so " chr(34) A_LoopFileFullPath chr(34) " content.xml"
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File

16 Aug 2019, 09:02

Glad to to see it worked out :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Reading The Contents Without Opening The Zip File

27 Aug 2019, 00:37

Her seferin 7z.exe tekrar mı açılıyor? I'm working with 30,000 files in size from 2 to 10 kb. The process takes too long. Is there a way to adapt it faster?
Any idea? Thank you so much.
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Reading The Contents Without Opening The Zip File

27 Aug 2019, 22:41

I think you would have to rethink your approach.
opening and closing a lot of files is generally much slower than a few files that are much larger...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 161 guests