TJ123 Posted July 20, 2012 Share Posted July 20, 2012 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 20, 2012 Moderators Share Posted July 20, 2012 TJ123,Use ShellExecute to get Windows to use the app registered for that file type: ShellExecute(@DesktopDir & "File_To_Open.txt")M23 n1maS 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mechaflash Posted July 20, 2012 Share Posted July 20, 2012 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.” Link to comment Share on other sites More sharing options...
TJ123 Posted July 20, 2012 Author Share Posted July 20, 2012 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. Link to comment Share on other sites More sharing options...
TJ123 Posted July 20, 2012 Author Share Posted July 20, 2012 (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 July 20, 2012 by TJ123 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now