Neimo Posted February 28, 2006 Posted February 28, 2006 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? #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
Moderators SmOke_N Posted February 28, 2006 Moderators Posted February 28, 2006 (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 February 28, 2006 by SmOke_N 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.
Neimo Posted February 28, 2006 Author Posted February 28, 2006 (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 _FileCreateBut it handles If Not _FileReadToArray("iTunesPlay.txt", $a_Playlists) Thenjust 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_PlaylistsIf Not _FileReadToArray("test.txt",$a_Playlists) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) ExitEndIfFor $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 February 28, 2006 by Neimo
Moderators SmOke_N Posted February 28, 2006 Moderators Posted February 28, 2006 Good deal... quick and painless 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now