Read and write files directly from/to Archive without extracting to the disk

Post your working scripts, libraries and tools
Posts: 11
Joined: 25 May 2017, 02:23

Read and write files directly from/to Archive without extracting to the disk

15 Jul 2018, 11:23

Hello everyone!

After so many attempts, finally succeeded in directly reading and writing from archive files without extracting to the disk.

I am not really sure if someone attempted this already. Searched in the forum but couldn’t find anything.

The final solution is so simple. But it took many trial and errors by evaluating different methods. Some of them worked, but with some shortfalls. I will explain “those” other methods in the end and the problems that I encountered. I hope it saves some time for anyone who is interested to check other possibilities.

Ok. Now, this is just a wrapper for 7-Zip (Undoubtedly, a brilliant piece of software).
7-Zip supports Stdin/Stdout functions. Directly writing and reading in console without extracting to the disk. The switches are “-si” and “-so”

There are 3 script files:
First one is 7-Zip Library (Wrapper for 7z.exe)
Second one is the “Support Script”
And the third is the “Example Script”

And rest all is self-explanatory.
7-Zip Library.ahk

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Support Script : WriteInConsole.ahk

Code: [Select all] [Download] GeSHi © Codebox Plus

;Support Script for Writing to Console Stdout
DetectHiddenWindows On
PID = %1%
ControlGetText, TextToStdOut, Edit1, ahk_pid %pid%
FileAppend %TextToStdOut%, *
Process, Close, %PID%

Example: Example.ahk

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Ok Now, about the other trial and errors. Hope someone can find a better solution to these.

Firstly, I tried using Windows native command "echo". It cannot print multi lines. I tried with "&echo." methods. Though the text seems to be in multi-lines, it is not a single stream, 7-Zip only captures either the first line or the last line (depends the method). Tried "Numlock On + Alt + 10" and "Alt+13" methods. They are not working in my Windows 7 x64 system. So, "echo" isn''t suitable. if So, we wouldn't need another supporting script. Also "^" is of no use. It does nothing

In search of a multi-line echo, i found CygWin "echo.exe" does it effortlessly. with -e switch Newline & Carriage return can be written to stream. But the only glitch is that, the text that we want to be written to archive to be processed by replacing all instances of "`n`r" to "\n\r". The real problem is if anywhere in the text(variable) "\n\r" exists, Cygwin echo.exe treats it as new line. So, this doesn't work flawlessly.

I also tried converting multi-line text to hex numbers as a single line parameter, but depends on the input text size, the string manipulations takes time. This works, but slow process.

And I played around with Wscript, and AHk's one of the wonderful functions FileOpen(), FileAppend *, but failed to do it from single script. At this time, I realised, the need of another process that can print the whole text in stdout stream, so managed to get it done in Ahk way. Simple script, few lines and Volla... its a magic

And the next challenge was passing the Variable to this support script in much simplest way. I know Postmessage, sendmessage all works for this. But there was a challenge. if I run the command through wscript(we need the output of the command to identify the success/error), the script will be busy until the command processed. So Post/Send message couldn't help. It works if I simply use Run/RunWait.

The next method, I tried by creating a Invicible GUI with a Edit control, Same thing happened. The GUI hangs, Support script couldn't access the gui.

As a final method, Notepad is a real Savior. It made all of it so easy.

Excuse me for all this lengthy post. I believe someone more knowledgeable can give me a better solution without depending on Notepad and a secondary script.

Thank You.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: rousni and 19 guests