Jump to content

Complete noob needs help with a short 7zip script.


Recommended Posts

Whats up guys,

I've never scripted or coded anything in my life (yet) but since the lack of an extractor with the features I need, I have to make a script. But as I said, I don't know sh** about it. Could you help me?

I think it can't be that complicated or long.

what I need:

extract a zip/rar/... by simple opening (doubleclick, auto-open after download completed, etc) it, in a new folder -> open the new folder.

period. no dialogues. just new folder->extract->open folder.

It can't be that much, am I right?

Please help me guys I need to extract stuff very open and this could save me much time and especially frustration.

Link to comment
Share on other sites

New Folder:

DirCreate ( "path" )

Extract file

$soft = "pathof7zip.exe"
$command = " x" ; --> make a space before
$command2 = " -o" ; --> make a space before
$file = " pathofthefile.zip" ; --> make a space before
$dest = "destinationfolder"

RunWait(@ComSpec & " /k " & $soft & $command1 & $file & $command2 & $dest, "", @SW_HIDE)

Open folder

$path = "c:temp"
Run("explore.exe " & $path)

The Extract code need a test, i don't have 7-zip.

Edited by johnmcloud
Link to comment
Share on other sites

  • Moderators

Hi, ImaCompleteNoob. Your first post stated "no dialogues" but if the file is not going to be in the same spot and named exactly the same every time, you might want to consider choosing it manually as part of your script. This is what I use:

$7z = "C:Program Files7-Zip7z.exe"
$var = FileOpenDialog("Unzip Utility", @ScriptDir, "All(*.*)")
ShellExecuteWait($7z, "e " & $var & " -o" & @ScriptDir & "Unzipped", "", "", @SW_HIDE)
ShellExecute(@ScriptDir & "Unzipped")

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Well I just want to go from

1. Arrow next to the downloaded archive in the download bar of Google Chrome

2. Open Location

3. Right-click

4. Extract with (whatever) "in new folder" (in the best case - less clicks)

5. scroll around and search for the folder

to

1. Open downloaded archive in the download bar of Google Chrome (with one click because I set the script as the default application for the files with extensions of archives [zip/rar/etc]).

2. See the unzipped archive folder in front of me and enjoy the comfort (whats popping up before the folder opens doesnt matter, as long as I don't have to do something before I can access the extracted folder)

..

To be honest, I don't get what both of you tried to tell me (I guess it's mostly my fault/lack of knowledge). Could you make it even more noobfriendly for me? :)

I mean, do I just have to copy and paste the whole code and just edit the paths?

Link to comment
Share on other sites

  • Moderators

Hi, ImaCompleteNoob. Don't worry about it, we've all been on day 1 before :) Below is my code, a little better defined for you. Let me know if this helps any. I don't use Chrome and thus don't have the download bar, but I'm sure we can help get you were you're going.

$7z = "C:Program Files7-Zip7z.exe" ;<---Change this directory to wherever you have the 7z.exe file. This allows you to set it once and forget it.

$var = FileOpenDialog("Unzip Utility", @ScriptDir, "All(*.*)") ;<--This opens a Windows style box, which allows you to browse for the file you want to unzip.
;If it is always going to be in the same spot, change the @ScriptDir to that directory (put it in "")

ShellExecuteWait($7z, "e " & $var & " -o" & @ScriptDir & "Unzipped", "", "", @SW_HIDE) ;<--This executes the command line 7zip utility, with the "e" for extract
;and the "o" so you can specify where you want the files saved. I am saving them to a folder called Unzipped, in the same directory as the script, but you can change this.

ShellExecute(@ScriptDir & "Unzipped") ;<---This command opens the directory so you can view the unzipped files.
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

So far so good, I got it working :)

But there are still 2 "problems"

1. How do I let it choose the file automatically? I thought by setting it as a default application for archives I could simply "open" it in that script if you know what i mean. Like when I open a picture or a video in vlc for example.

2. Is there a way to make the output-folder name, the name of the choosen file automatically too? Variables?

Edited by ImaCompleteNoob
Link to comment
Share on other sites

  • Moderators

Hi, ImaCompleteNoob. As far as choosing the file automatically, it depends on where the file will be, and if it will be the only zip file in that directory. Something like this would save the files to a directory called Unzipped on your Desktop...

$7z = "C:Program Files7-Zip7z.exe" ;<---The full path to your 7z.exe file.

$loc = @DesktopDir & "Unzipped" ;<--The path to where you want the files unzipped.

$search = FileFindFirstFile($loc & "*.7z") ;<--Searches through dir for all .7z filenames.

$file = FileFindNextFile($search) <---returns the very first .7z file it finds.

ShellExecuteWait($7z, "e " & $loc & "" & $file & " -o" & $loc & "" & StringTrimRight($file, 3), "", "", @SW_HIDE)
^^--This executes the command line 7zip utility, extracts all the files and places them into a directory the same name as the file.

FileMove($loc & "" & $file, $loc & "" & StringTrimRight($file, 3), 1) ;<--Moves the zip file into the directory with the unzipped files.
;FileDelete($loc & "" & $file) <--If you don't want to save the zip file, uncomment this line and delete the one above.
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks again for your help logan but it didn't work for me (at least not as I expected)

anyway by accident I found an application that does exactly what I want/need. not more, not less (its name is "Extract Now" if anyone is interested) never heard of it before

however thank you for trying to help me. I think I'll find some more tasks to try out with AutoIt and get to back to this forum very soon again. :)

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...