tags:

views:

141

answers:

2

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

A: 

File.applicationDirectory is a read only directory.

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

Umesh
Interesting, it seems the documentation is inconsistent because it turns out you can delete from that directory.
Ryan K
Perhaps it is the difference between debug and installed?
Joel Hooks
A: 

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!

Ryan K
Wow. I love it when people comment the code to identify why they are doing something they shouldn't be. The main reason why AIR doesn't allow you to easily write to that dir is because SWF files in there are trusted. So writing new SWF files there can open up security holes. It's not that you shouldn't be able to do it (because obviously you can) it's that by doing so can cause problems. And that is why the practice is discouraged through the basic errors you will get by trying to write to the applicationDirectory.
James Ward
Thanks for the additional insight James. I had another suggestion from someone on the adobe forums to use File.applicationStorageDirectory instead of File.applicationDirectory. This is a much better place to write temporary log files.
Ryan K
Yes! That is the best place for that. Should have mentioned that. :)
James Ward