3 Replies Latest reply on Oct 4, 2006 10:40 AM by Newsgroup_User

    deleting contents of txt file with fileIO

    Level 7
      I need to replace the contents of a text file. I can open and write to
      the file ok with the fileIO xtra, but when I write to the file it simply
      writes over what's already there. So if what was there originally was
      longer than what I want to replace it with, I still see the left overs.
      For example, say the original file had the word "exponential" in it,
      and I wanted to replace it with the word "sum." What I would end up
      with would be "sumonential"

      Is it possible to delete the contents of the text file before writing to
      it so that I don't have this problem?

      Thanks
        • 1. Re: deleting contents of txt file with fileIO
          Ex Malterra Level 1
          only way i've found to do it is to delete and recreate the file. if you're using javascript delete is funky, look in livedocs.
          • 2. Re: deleting contents of txt file with fileIO
            Level 7
            Yeah, I just figured that one out. I used the buddy API functions to
            delete the file. Then I used fileIO to re-create and edit it. Works
            fine, but kind of goofy to have to do it that way.
            • 3. Re: deleting contents of txt file with fileIO
              Level 7
              You can also delete it with fileIO's own delete() method. No need for
              two xtras.

              You could try and open the file, if it's status is -37, it does not
              exist and you can create it and write to it. Otherwise, delete it first.

              like:

              theFile.openFile(filePath, 1)

              if (theFile.status() = -37) then
              -- file does not exist appearantly
              else
              -- delete file before writing to it
              theFile.delete()
              theFile.closeFile()
              end if
              theFile.createFile(filePath)
              theFile.openFile(filePath, 2)
              theFile.writeString(content)

              Not sure if kind of raising the error is the preferred way to go, but it
              does the trick.

              Manno


              Word One - Denver wrote:
              > Yeah, I just figured that one out. I used the buddy API functions to
              > delete the file. Then I used fileIO to re-create and edit it. Works
              > fine, but kind of goofy to have to do it that way.

              --
              ----------
              Manno Bult
              manno@xs4all.nl