Jump to content

Saving to a text file


 Share

Recommended Posts

$DATA = ""
            $NUM = _GUICtrlListBox_GetCount($List1)-1
            For $INDEX = 0 To $NUM
                $DATA &= _GUICtrlListBox_GetText($List1,$INDEX) & @CRLF
            Next
                        
            $bboy= FileOpen("bin\bboy.txt",2)
            FileWrite($bboy,$DATA)          
            FileClose($bboy)

What's wrong with this? It doesn't open a file nor create a file..

Link to comment
Share on other sites

Does the sub directory "bin" already exist?

Edit: @Mattraks,

you don't need to specify the full path. And mode 1 is only required if you want to append the output to the file.

Edited by ResNullius
Link to comment
Share on other sites

yes the bin directory exists..

Can you post more (or a workable sample) of your script so we can test to see if we get the same results.

Also, what OS are you running on, and what directory is the script running in?

Edited by ResNullius
Link to comment
Share on other sites

Case $Button1
            $addfile = FileOpenDialog("Add A File","","All (*.*)")
            if $addfile <> 1 Then 
                _GUICtrlListBox_AddString ($List1,$addfile)
            EndIf
            
        Case $Button2
                      $DATA = ""
            $NUM = _GUICtrlListBox_GetCount($List1)-1
            For $INDEX = 0 To $NUM
                $DATA &= _GUICtrlListBox_GetText($List1,$INDEX) & @CRLF
            Next
                        
            $bboy= FileOpen("bin\bboy.txt",2)
            FileWrite($bboy,$DATA)          
            FileClose($bboy)

That's just it..

Link to comment
Share on other sites

Case $Button1
            $addfile = FileOpenDialog("Add A File","","All (*.*)")
            if $addfile <> 1 Then 
                _GUICtrlListBox_AddString ($List1,$addfile)
            EndIf
            
        Case $Button2
                      $DATA = ""
            $NUM = _GUICtrlListBox_GetCount($List1)-1
            For $INDEX = 0 To $NUM
                $DATA &= _GUICtrlListBox_GetText($List1,$INDEX) & @CRLF
            Next
                        
            $bboy= FileOpen("bin\bboy.txt",2)
            FileWrite($bboy,$DATA)          
            FileClose($bboy)

That's just it..

The problem is with the behaviour of FileOpenDialog().

From the "Remarks" section of that command in the helpfile:

@WorkingDir is changed on successful return.

Insert this line:
MsgBox(0,"","ScriptDir is: " & @ScriptDir & @crlf & "WorkingDir is: " & @WorkingDir)

before

$bboy= FileOpen("bin\bboy.txt",2)

and you'll see what the problem is: bboy.txt is attempting to be opened in the WorkingDir, which changes after you add a file to the list.

So in that sense, Mattraks was right: add @SciptDir to your FileOpen() command.

$bboy = FileOpen("@ScriptDir & "\bin\bboy.txt",2)
Edited by ResNullius
Link to comment
Share on other sites

Just save the working Dir and set it back afterwards :P

$__OLD_WORKING_DIR = @WorkingDir
$addfile = FileOpenDialog("Add A File","","All (*.*)")
FileChangeDir($__OLD_WORKING_DIR)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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...