开发者

How can you delete a file in the application directory?

We are writing log files to File.applicationDirectory and want to clean out old log files. The question is ho开发者_运维百科w 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


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.


File.applicationDirectory is a read only directory.

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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜