Sign in to follow this  
Followers 0
xuzo

Extreme beginner with ridiculous questions! ;( How open file with path?

15 posts in this topic

I've tried this example but didn't work. I put the au3 file in a new folder and created a text.txt in the same folder but that didn't work either...!

Local $file = FileOpen("test.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
FileClose($file)

So I created a text file, put it in C, and then changed to the line to this:

Local $file = FileOpen("C:\test.txt")

Still didn't work, very stupid question and I've looked at the help and reading the book, but what is the syntax for file path? And what would be the syntax for opening applications that are portable (not in program files folder).

What I'm trying to acheive is what I used in Vista-Task called {curdir} so I put all my files in a folder and I can move the folders.

Thanks,

Share this post


Link to post
Share on other sites



Try ShellExecute FileOpen is used for functions such as FileReadLine.

From my understanding of the question you just want to open a file.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi John,

Thank you but that line of code is pretty complicated...for a rookie like me!

I'm looking for the syntax to open a file called text.exe using notepad or wordpad (with the command to use the software, not just a .text file) in C drive at root?

Cheers!

Something like:

Run("C:test.txt" "C:programfilesnotepad")

I'm looking for simple syntax to open a file with the directory path + the application to use to open it.

or something like that?

Edited by xuzo

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

ShellExecute ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] )

ShellExecute("Filename.ext", "", "", "OPEN")

If the default application that opens that filetype is undesireable, try

ShellExecute("C:pathsome_other_program.exe", "Filename.ext", "", "OPEN")
Edited by mechaflash213

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

Hi Venix,

yes indeed, I just want to know how to open a file using software X. For example:

open pathx.html doc with either Firefox, google chrome or IE, all HTML files but opened with different applications, I also don't know how to assign paths.

In plain English:

AutoIT(please open x.html situated in D drive with firefox :D)

Thanks guys and sorry for my ignorance again!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi Scott, I've had about 7 beers... and 9:30 pm in Thailand but will give that a shot :D

Edited by xuzo

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ok it worked!

ShellExecute("D:portable_appsportable_programingportable_NotePadPlusNotepad++Portablenotepad++portable.exe", "D:portable_appsportable_programingportable_NotePadPlusNotepad++Portabletesting.txt", "", "OPEN")

However, isn't there a shorter way to do this? like?

{curdir} or something?

Edited by xuzo

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

lol you called me Scott...

$sProgram = "D:portable_appsportable_programingportable_NotePadPlusNotepad++Portablenotepad++portable.exe"
$sFile = "D:portable_appsportable_programingportable_NotePadPlusNotepad++Portabletesting.txt"
ShellExecute($sProgram, $sFile, "", "OPEN")

Short answer: No

But you could reference the directory in a variable and concatenate the app/file

$sDir = "D:portable_appsportable_programingportable_NotePadPlusNotepad++Portable"
ShellExecute($sDir & "notepad++portable.exe", $sDir & "testing.txt", "", "OPEN")
Edited by mechaflash213

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

However, isn't there a shorter way to do this? like?

{curdir} or something?

What EXACTLY do you mean by "a shorter way" and "{curdir}"? If you mean to use the current script directory, use @ScriptDir, if you mean use the current working directory, use @WorkingDir. The former will give you the full path that the script is sitting in, the latter will give you the full path to whereever you've set the working directory which will default to the script's directory. Both will not end in a trailing backslash, so you'd have to add it yourself.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I think he wanted to know if he could reference the directory that the program is in, because he holds his files in the same directory... and shorten the "Argument" to just the filename.

Made an edit to my post #9

Edited by mechaflash213

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

Hi Scotts,

Yes something like that.

{curdir}\25_char_headlines.txt

That's what it looks like in Vista-Task Studio, means the script, and the file is in the same folder, can be moved around as portable.

I think this:@ScriptDir or @WorkingDir is the solutions but how do I code that?

Something like this?

ShellExecute("C:\path\some_other_program.exe", "@scriptdir/Filename.ext", "", "OPEN")

you guys are great, I'll have to test it in the morning

Cheers!

post-73961-0-16450300-1340809838_thumb.j

Share this post


Link to post
Share on other sites

You'd use ShellExecute("C:pathsome_other_program.exe", @ScriptDir & "Filename.ext", "", "OPEN"). The ampersand is used to merge 2 strings together, and you can't have the macros or variables inside quotes.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks BrewMan and everybody,

Great forum!

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Can close post, working fine 100%:

ShellExecute("D:portable_appsportable_web_designKomPoser_NVUKompoZerPortable.exe", @ScriptDir & "input.html", "", "OPEN")

Thanks!

Edited by xuzo

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