Reputation: 5280
Many a times we need to automatically execute files based on their extentions. I guess it can be done through AUTOIT. Can someone please direct me on this?
This was helpful in getting the extensions.
$parts = StringSplit($file,"\.",0)
$ext = $parts[$parts[0]]
$filename = $parts[$parts[0] - 1]
Then how do you set up the conditional execution?
Upvotes: 0
Views: 930
Reputation: 86
Wouldn't ShellExecute work better than running a bunch of Switch statements? If you have file associations set up for the file extensions, then ShellExecute will open the default program for that extension automatically.
Unless you're trying to run a specific program, that isn't set as the default for the file type for example run Chrome on a HTML file while IE is the default program for HTML files, then it shouldn't need a lot of extra conditional statement work.
Upvotes: 0
Reputation: 7160
Assuming you want to be comparing against a range of extensions, the easiest method is a switch statement:
Switch $ext
Case "txt"
; What to do with text files
Case "htm", "html"
; Example of matching more than one extension
Case Else
; Extension wasn't any of the above
EndSwitch
What I think you actually want to do is let the computer decide what the best program to execute a file is. This information is stored in the registry along with the extension (in HKEY_CLASSES_ROOT) but you don't need to know any of that, as a special function called ShellExecute is provided. This uses the extension to run the default handler for the file (with the option of using a given "verb"). e.g:
ShellExecute("C:\Test.txt")
Upvotes: 2