Sign in to follow this  
Followers 0
The Kandie Man

Help with File Association

10 posts in this topic

#1 ·  Posted (edited)

I just recently started programming and i am not very far into it yet. I just recently learned about autoit and i have made many programs. I am stuck now and i am not sure what to do.

What i want is my script (when compiled) to open up files when a user double clicks a file with the extension .asdf. If the user double clicks a file, then the OS sends the .exe script instructions to open the file that the user has just double clicked. I don't know what this is called or how the program listens for the instructions the OS gives it. I was just wondering if such a thing was possible.

Here is a look at the very basic program i wrote. I wrote it for MSN Messenger in case you were wondering since new versions don't allow the sending of many file types. It works by renaming files that have names like "setup.exe.asdf" to "setup.exe"

#include <GUIConstants.au3>

GUISetState ()

While 1;Don't even need since it doesn't loop but i do it anyway out of habit;)

    $msg = GUIGetMsg ()

    $file = FileOpenDialog("Open", @MyDocumentsDir & "\My Received Files\", "ASDF (*.asdf)")


    $len = StringLen($file); Get the length of the file
    
    $truefilenamelength = $len - 5; Remove last 5 digits or .asdf
    
    $actualfilename = StringLeft($file, $truefilenamelength); Count only characters of actual file excluding asdf
    
    FileCopy  ($file, $actualfilename); copy the file to rename it

    FileRecycle ( $file );delete the file with the extension asdf

    exit

Wend

The program works, but it opens an open dialogue when the user double clicks the file they want to open. I want the program not to even show a dialogue if possible.

Please help :)

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites



You could compile it as an exe, and associate the asdf extension to the executable...I'm not 100% sure it will open the file (instead of file dialog), but it might...you could also check cmdline params to see if it is passed there...


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I have autoit v3.1.1. I have associated all .asdf files on my computer with a compiled .exe of the script above. When i double click an .asdf file on my computer, it opens the compiled script above(.exe form), but the executable above doesn't open the file. I have looked and i can't find anything that can do this or at least don't know the name. Is there a function or a parameter that listens to see if the OS is giving it the location of a file to open when it runs.

What i am trying to do is make my program open .asdf files like Word opens .doc files, but i don't know how to make the script do that.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Search the helpfile for $CMDLine..

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I just tested it, give me a minute and I'll write up a few lines of code that you'll want

If $CmdLine[0] > 0 Then
        $file = $CmdLine[1]
    Else
        $file = FileOpenDialog("Open", @MyDocumentsDir & "\My Received Files\", "ASDF (*.asdf)")
    EndIf
    FileMove($file, StringTrimRight($file, 5), 1)

I have to apologize now, I had to clean up the code, I just can't stand using a sledgehammer to get a nail through a piece of wood :)

Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Yes, you guys got at what i wanted. Thx a bunch, been up all night trying to figure it out. Just didn't know what it was called. Thank you to MSLx Fanboy for writing code. Like i said, i am a newbie and the best way i learn is looking at other peoples work and examples in the help file. So far this has been the only thing that has stumped me.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Just finished the code, look at my previous post (#6)


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Thx again. Sorry about the mess i made. Like i said, i am a newbie. Thanks for helping me.


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

My pleasure. Keep working on some scripts, it makes it much easier to understand logic... (loops, conditionals, etc)


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
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
Sign in to follow this  
Followers 0