Jump to content

Beginner's question


Recommended Posts

Hello,

I am just beginning to experiment using AutoIt, so please be patient.

I have read some documentation.

I would like to learn some scripting skills, and I found the following problem would be a great place to start.

So, here we go.

I use 7 zip all the time to extract all sorts of archives, but have become annoyed by the GUI that kept popping up when all I wanted was to unarchive a file. What I wanted was something really like The Unarchiver for mac.

I have created the following batch file that runs 7 zip from the command line with only the progress bar appearing.

"D:\Path\to\7\zip\7zG.exe" x %1 -o%cd%\* 
del %1

The first line runs 7zip from the command line using the x switch, which is there to extract. The o switch allows me to extract the archive to a folder with the same name as the archive.

Then I delete the archive.

I would like to code this using autoit, I think It would be a great way to start learning it.

What I tried was Run, but I noticed it did not allow you to use switches.

Any help or any links pointing to documentation would be greatly appreciated.

Ps: I would like to use filerecyle instead of the del equivalent.

Link to comment
Share on other sites

ShellExecuteWait("D:\Path\to\7\zip\7zG.exe", 'x "' & $CmdLine[1] & '" -o"' & @WorkingDir & '\*"')
;~ FileDelete($CmdLine[1])
FileRecycle($CmdLine[1])

Better use ShellExecuteWait for such a command, it's easier. :mellow:

The %1 of a batch file is replaced with $CmdLine[1]

%CD% should be @WorkingDir in AutoIt

Also don't forget the quotes. %1 or %CD% could have spaces in their names.

Edited by JFX
Link to comment
Share on other sites

AutoIt can make DLL calls and use a COM interface (7za.dll) also. I believe there is already a 7zip UDF posted that uses it.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I've noticed an odd 'bug' tough.

When extracting very small zip files to my desktop, it does not show the newly created folder, although it is present and visible when I go see the desktop folder in explorer.

I did not have this issue when using my batch file.

Could it be related to autoit?

Link to comment
Share on other sites

Why do you use "&" between the different shellexectue parameters? Are they necessary for the syntax?

Only where you want to concatenate variable values with the literal string parts:

'x "' -- literal string

& $CmdLine[1] & -- variable value

'" -o"' -- literal string

& @WorkingDir & -- variable value

'\*"' -- literal string

If $CmdLine[1] (first command line parameter passed to the script) is "C:\MyDir\MyFile.7z", and @WorkingDir = "C:\Temp", then that all becomes one string as:

'x "C:\MyDir\MyFile.7z" -o"C:\Temp\*"'

This entire string is passed to the executable (7zG.exe) in ShellExecute() as the complete command line parameters.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...