Sign in to follow this  
Followers 0
Neimo

_FileWriteFromArray won't write... I'm stumped

4 posts in this topic

So I've tried every thing I can think of, including deleting and then writing to array element [1] instead of [0]. I've tried leaving the newly created iTunesPlay.txt file blank, and also entered numbers on different lines then saving. The _FileWriteFromArray command just won't write, even though I know the array has the executable's path according the MsgBox. If it makes any difference, I'm using the AutoIt Beta because I need the _IsPressed function. What's wrong here? :o

#include <Array.au3>

#include <file.au3>

Dim $a_Playlists, $iTunesLocation

If Not FileExists(@ScriptDir & "\iTunesPlay.txt") Then

_FileCreate(@ScriptDir & "\iTunesPlay.txt")

MsgBox(0, "iTunes Playlist", "Created iTunesPlay.txt")

EndIf

If Not _FileReadToArray("iTunesPlay.txt", $a_Playlists) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

; _FileReadToArray creates a new element with the number of elements in the array.

; Delete the created element or a new one will be added every time this is run

_ArrayDelete($a_Playlists, 0)

_ArrayDisplay( $a_Playlists, "_ArrayDisplay() Test" )

$iTunesLocation = $a_Playlists[0]

; Since iTunesPlay.txt has just been created, there is no location stored for iTunes.exe

; BUT YOU CAN PICK ANY .EXE FILE FOR THIS CODE SNIPPET

If $iTunesLocation = "" Then

$iTunesLocation = FileOpenDialog("iTunes Playlist", "C:\", "Executable (*.exe)", 1, "iTunes.exe")

MsgBox(0, "iTunes Location is", $iTunesLocation)

EndIf

$a_Playlists[0] = $iTunesLocation

MsgBox(0, "$a_Playlists[0] is", $a_Playlists[0])

; Write the location of iTunes.exe

If Not _FileWriteFromArray("iTunesPlay.txt", $a_Playlists) Then

MsgBox(4096,"Error", " Error writing log to Array error:" & @error)

EndIf

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try using the actual path to the .txt file.

_FileWriteFromArray('C:\iTunesPlay.txt', $a_Playlists)

Edit:

Also, if it's creating a file, and your reading the file you just created to an array, there is no information there?

Edit2:

Here, this is tested and works:

#include <Array.au3>
#include <file.au3>

Local $a_Playlists = '', $iTunesLocation = '', $FilePath = @ScriptDir & "\iTunesPlay.txt"

If Not _FileReadToArray($FilePath, $a_Playlists) Then
    _FileCreate($FilePath)
    Do
        Sleep(10)
    Until FileExists($FilePath)
    _FileReadToArray($FilePath, $a_Playlists)
EndIf

#cs
; This could be rather redundant, since there still won't be information in that file
If UBound($a_Playlists) = 0 Then
    $FilePath = FileOpenDialog('Find iTunes Playlist', @HomeDrive, 'Application (*.exe)')
    _FileReadToArray($FilePath, $a_Playlists)
EndIf
#ce 

; Write the location of iTunes.exe
If Not _FileWriteFromArray(@HomeDrive & "\iTunesPlay.txt", $a_Playlists, 1) Then
MsgBox(4096,"Error", " Error writing log to Array error:" & @error)
EndIf
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

That works, thank you. I just tried

_FileWriteFromArray(@ScriptDir & "\iTunesPlay.txt", $a_Playlists)

as well and that works too, so now it can be directory indepedant, just like I need it. I wish I'd done that since I did it for the FileExists and _FileCreate

But it handles

If Not _FileReadToArray("iTunesPlay.txt", $a_Playlists) Then

just fine.

Nevertheless, it just doesn't make sense to me how that is necessary, but this code works without it:

#include<Array.au3>

#include <file.au3>

Dim $a_Playlists

If Not _FileReadToArray("test.txt",$a_Playlists) Then

MsgBox(4096,"Error", " Error reading log to Array error:" & @error)

Exit

EndIf

For $x = 1 to $a_Playlists[0]

Msgbox(0,'Record:' & $x, $a_Playlists[$x])

Next

_ArrayDelete($a_Playlists, 0)

$a_Playlists[0] = 42

_FileWriteFromArray("test.txt", $a_Playlists)

Thanks again, I'm glad to get it working.

Edit Just read your edits and like your code better.

Edited by Neimo

Share this post


Link to post
Share on other sites

Good deal... quick and painless :o


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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