Jump to content

Writing to a file


Surgery
 Share

Recommended Posts

Ok, here's the script snippet:

Local $path = FileOpenDialog("Find Launcher", "C:\", "Launcher (index.html)");
    Local $file = FileOpen("pointer.txt", 2);
    FileWriteLine($file, $path);
    MsgBox(0, "Status", $path);
    FileClose($file);

it writes the file location to the pointer.txt file fine if the file is in the same folder as the script executable. but if it isn't it just doesn't write anything, even though the msgbox prints out the correct path. It'd make a little more sense if the msgbox also printed nothing, but I don't understand why it isn't writing correctly. Thanks.

Link to comment
Share on other sites

Ok, here's the script snippet:

Local $path = FileOpenDialog("Find Launcher", "C:\", "Launcher (index.html)");
    Local $file = FileOpen("pointer.txt", 2);
    FileWriteLine($file, $path);
    MsgBox(0, "Status", $path);
    FileClose($file);

it writes the file location to the pointer.txt file fine if the file is in the same folder as the script executable. but if it isn't it just doesn't write anything, even though the msgbox prints out the correct path. It'd make a little more sense if the msgbox also printed nothing, but I don't understand why it isn't writing correctly. Thanks.

If your saying what I think you are, then it's because $path is written to pointer.txt if certain things are true. The MsgBox(), however, will appear no matter what. Does this help?

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

If your saying what I think you are, then it's because $path is written to pointer.txt if certain things are true. The MsgBox(), however, will appear no matter what. Does this help?

Ah, yes. You are right. However, I forgot to say that in my debugging I have tried capturing the result of the FileWriteLine call and MsgBoxing that, and I get 1. And when I open the file it was supposed to have written to either there is nothing there or there is no change.
Link to comment
Share on other sites

Sorry to bump this, but this is a major problem, and if it's a language issue I'd like to know so I can move on and find another language.

When you choose a file in another folder the working directory is set to that folder. So when you open the file to write it will be created in that folder. You need to set the working directory back before you open the file to write.

Local $currentworkingdir = @WorkingDir
Local $path = FileOpenDialog("Find Launcher", "C:\", "Launcher (index.html)");
FileChangeDir($currentworkingdir)
Local $file = FileOpen("pointer.txt", 2);
FileWriteLine($file, $path);
MsgBox(0, "Status", $path);
FileClose($file);

EDIT Correct "file to read" to "file to write"

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...