Sign in to follow this  
Followers 0
fil

Copy file path to a txt file

5 posts in this topic

Hi everyone.

First let me say that I am new to AutoIT so probably there is something fundamental that I miss in my problem.

What I want to do is very easy.

I have created a GUI (see attachment) and I have an input field.

I created a "Browse" button when you click it the "Open File Dialog Box" appears and the path of the selected file is passed to the input box.

When you click on the "Copy" button the path should be written to a txt file. But it does not.

I created another button calles "Show Box" that shows the value of the input box and it seems to be ok.

The thing is that if I just write some text in the input box and click copy, everything works fine.

Even if I copy paste the path (NOT using the "Browse" button) it works fine.

So, I would really appreciate any help regarding how to make it work with the "Browse" button.

PS: Check the attachment. It is the GUI mentioned before.

Thank you.

fil_file.au3

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It's putting "file.txt" in the directory you browse to. You'll need to change Working Directory or specify a full path when you write to file.txt.

Check the help file for FileOpenDialog(), it sets @WorkingDir on successful return...

Edited by MrMitchell

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Welcome to Autoit!

And for a first post, that's a darn fine example script!

In addition to MrMitchells valid point, I can offer the following tips:

When you created your InputBox control, you assigned the controlID created to the variable $path.

If you make one little change to your script all the ID's assigned to your controls can change, so when referencing a control, you ought to use the assigned variable rather than a hard-coded controlID, so

GUICtrlRead(4,1)
ought to be
GUICtrlRead($path,1)

There are two methods for using FileRead() and FileWrite(), one does not require FileOpen() or Fileclose() commands, and uses a file/pathname as it's argument. The other method uses a file handle created with a FileOpen() statement, like:

$filehandle = FileOpen("file.txt")
FileWrite($filehandle, $temp_path)
FileClose($filehandle)
You're mixing the two methods...

Also I don't think FileFindFirstFile() is appropriate for your usage, you'd find a simple FileExists() command more to your liking I think.

Edited by Spiff59

Share this post


Link to post
Share on other sites

Thank you guys for the help.

I fixed it with @ScriptDir and it works fine.

Thak you MrMitchell for the help

Spiff59 I really appreciate your tips how to handle files and the values in my inputs.

Thanks once more.

Share this post


Link to post
Share on other sites

Script was clean and easy to read, very nice...makes it much easier to help and get help ;)

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