2 Replies Latest reply on Nov 19, 2009 9:14 AM by Jeff Swartz

    How can you delete a file in the application directory?

    retroryan

      We are writing log files to File.applicationDirectory and want to clean out old log files.  The question is how do you delete files out of that directory?  When I try and delete old log files out of this directory it gives a security exception.  Is there anyway around this?

       

      I know you are not supposed to write to File.applicationDirectory, but we are writting are logs there anyways.  So please don't just say don't do that!

       

      Thanks,

      Ryan

        • 1. Re: How can you delete a file in the application directory?
          retroryan Level 1

          I found the answer shortly after posting.  I was lookin in FileTarget of how the write log file into the application directory and found t

          his gem:

           

                      var logFile:File = this._logDirectory.resolvePath(filename);
                      logFile = new File(logFile.nativePath); // Hack to get around SecurityError if log directory exists within the application directory

           

          So you just specify the full native path and not a relative path from the application directory and you can do whatever you want.  Interesting security model

          • 2. Re: How can you delete a file in the application directory?
            Jeff Swartz Level 3

            Use the application storage directory: File.applicationStorageDirectory. This directory is specific to the application, where you can store data, such as log files. And you can add and remove files to this directory without restrictions.