How can you delete a file in the application directory?

久未见 提交于 2019-12-18 09:42:41

问题


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:


File.applicationDirectory is a read only directory.

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




回答2:


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.




回答3:


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!



来源:https://stackoverflow.com/questions/1760893/how-can-you-delete-a-file-in-the-application-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!