Jump to content

Writing to a file..


Recommended Posts

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
Link to comment
Share on other sites

$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]
Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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