How can you delete a file in the application directory?

前端 未结 3 892
温柔的废话
温柔的废话 2020-12-22 11:02

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 de

相关标签:
3条回答
  • 2020-12-22 11:56

    Another trick, for security workaround

    var fileLoc:File= File.applicationDirectory.resolvePath("some.log");
    var file:File=new File(fileLoc.nativePath);
    fileStream.open(file,FileMode.WRITE);
    

    The second file object can alter the file withot any problem.

    0 讨论(0)
  • 2020-12-22 11:58

    I found the answer shortly after posting. I was looking in FileTarget of how they write the log file into the application directory and found this 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!

    0 讨论(0)
  • 2020-12-22 12:00

    File.applicationDirectory is a read only directory.

    http://livedocs.adobe.com/flex/3/langref/flash/filesystem/File.html

    0 讨论(0)
提交回复
热议问题