cppman Posted March 11, 2006 Posted March 11, 2006 Whenever the File Open dialog comes up, i pick my files, and hit open, it will not create the file, "files.txt", but when i click cancel, it will create a blank file called, "files.txt".. Func AddFile() FileClose("files.txt") $AFile = FileOpenDialog("Select Files", "", "All Files (*.*)", 4) $FileCount = StringSplit($AFile, "|") $File = FileOpen("files.txt", 1) For $i = 1 to $FileCount[0] FileWriteLine($File, $FileCount[1] & $FileCount[$i]) Next EndFunc Miva OS Project
eynstyne Posted March 11, 2006 Posted March 11, 2006 $AFile = FileOpenDialog("Select Files", "", "All Files (*.*)", 4) if @error then $Afile = "" exit endif $FileCount = StringSplit($AFile, "|") $File = FileOpen("files.txt", 1) For $i = 1 to $FileCount[0] FileWriteLine($File, $FileCount[1] & $FileCount[$i]) Next I added the if @error so that when you press cancel, it doesn't create anything. F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]
cppman Posted March 11, 2006 Author Posted March 11, 2006 (edited) thanks, but i was looking to see why it was'nt writing the lines to the file after the person selects OPEN. hmm.... after i close the entire application, then it writes to the file. y? Edited March 11, 2006 by CHRIS95219 Miva OS Project
cppman Posted March 11, 2006 Author Posted March 11, 2006 (edited) oh! Thanks, i did'nt see that. YAY! *Its Larry*. Edited March 11, 2006 by CHRIS95219 Miva OS Project
billmez Posted March 11, 2006 Posted March 11, 2006 $AFile = FileOpenDialog("Select Files", "", "All Files (*.*)", 4) if @error then $Afile = "" exit endif $FileCount = StringSplit($AFile, "|") $File = FileOpen("files.txt", 1) For $i = 1 to $FileCount[0] FileWriteLine($File, $FileCount[1] & $FileCount[$i]) Next I added the if @error so that when you press cancel, it doesn't create anything. For $i = 1 to $FileCount[0] FileWriteLine($File, $FileCount[1] & $FileCount[$i]) Next $FileCount[0] = the number of elements in the array $FileCount[1] = the directory $FileCount[2] is the first file name So I believe you will want For $i = 2 to $FileCount[0] because 1 is a constant for all listed files. Also, there is no directory slash added, so you may want to use FileWriteLine($File, $FileCount[1] & "\" & $FileCount[$i]) I would also use a directory with the file.text, even if it is @ScriptDir & "\", and if you do not wish to append a previous file use 2 instead of 1 with the file open. I would not start the function by closing a previously opened file handle as you have Func AddFile() FileClose("files.txt") I would close it after the loop before the end of the function
cppman Posted March 11, 2006 Author Posted March 11, 2006 (edited) For $i = 1 to $FileCount[0] FileWriteLine($File, $FileCount[1] & $FileCount[$i]) Next $FileCount[0] = the number of elements in the array $FileCount[1] = the directory $FileCount[2] is the first file name So I believe you will want For $i = 2 to $FileCount[0] because 1 is a constant for all listed files. Also, there is no directory slash added, so you may want to use FileWriteLine($File, $FileCount[1] & "\" & $FileCount[$i]) I would also use a directory with the file.text, even if it is @ScriptDir & "\", and if you do not wish to append a previous file use 2 instead of 1 with the file open. I would not start the function by closing a previously opened file handle as you have Func AddFile() FileClose("files.txt") I would close it after the loop before the end of the function Yeah, thanks, i already got it all setup, i just used that as a little Quick Demo of what i was doing... about that FileClose() at the beginning, I did that because a while back, i had opened a lot of files, and never closed them... so i was'nt able to Open any mroe files, so i did that, and it worked for me... so yeah, at first i thought that was what my problem was. so i did that. Edited March 11, 2006 by CHRIS95219 Miva OS Project
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