Sign in to follow this  
Followers 0
TJ123

run a .txt file on desktop...

5 posts in this topic

I am trying to run a .txt file on a windows desktop so as to view the contents, similar to if I had double clicked on the file icon.

I tried using Run (@DesktopDir & "\File_To_Open.txt"), but it does not seem to work, perhaps because a .txt is not an executable?

I can open notepad with something like Run ( @WindowsDir & "\notepad.exe" ), and then I could try to have notepad navigate to the file and open it, but is there an easier way?

Thanks for any help,

TJ.

Share this post


Link to post
Share on other sites



TJ123,

Use ShellExecute to get Windows to use the app registered for that file type: :)

ShellExecute(@DesktopDir & "File_To_Open.txt")

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

The reason why your Run() command didn't work is probably because your @DesktopDir includes spaces. Run() requires proper use of quotes to target the file to run as it imitates the CMD Run command syntax.

Run ('"' & @DesktopDir & 'File_To_Open.txt"')

However, I try to use ShellExecute() in place of Run() if I had a choice between the two.


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Thanks very much Melba23! It may have taken me a while to find that one in the AutoIt Help. I did do a few quick searches in the forum, but did not find an answer to this one. It worked perfectly, I guess you already knew that!

Thanks again,

TJ.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Mechaflash,

Thanks for your advice, I will keep that in mind. I can use FileWriteLine (@DesktopDir & "File_To_Open.txt") to write to the file, so I assumed it would also work as the path to run the file. I understand from what you are saying that the additional quotes are required for the CMD syntax that is used by AutoIt to run a file, I was not aware of this, so thanks for bringing it to my attention!

TJ.

Edited by TJ123

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