« New version of PixelWindow | Main | New ActionScript and Flex Spell Checking Engine on Adobe Labs »
July 13, 2009
Ignoring Hidden Files in AIR
I'm writing an AIR application that recursively traverses the file system, and I ran into an interesting problem. I discovered a file called permStore which exists at the time that it's read, but just milliseconds later, it no longer exists. I wasn't able to definitively determine what this temporary file is for, but it exists (for very short periods of time) inside the .Spotlight-V100 directory which essentially means that it's supposed to be hidden, it's owned by the operating system, and it's really none of my business.
I determined pretty quickly that nothing in the .Spotlight-V100 directory was relevant to my program, so I decided I would just skip the entire directly, and any other hidden, or "dot" file, as well. One simple line of code did the trick:
if (!dir.isDirectory || dir.isHidden || !dir.exists || dir.name.search(/^\..*$/) != -1) return;
Here's the full function I wrote for recursively traversing a directory, ignoring hidden and "dot" files, and stopping at length determined by MAX_FILES.
private function iterateFiles(dir:File):void
{
if (!dir.isDirectory || dir.isHidden || !dir.exists || dir.name.search(/^\..*$/) != -1) return;
var listing:Array = dir.getDirectoryListing();
for each(var f:File in listing)
{
if (this.fileList.length >= this.MAX_FILES) break;
if (f.isHidden || !f.exists || f.name.search(/^\..*$/) != -1) continue;
if (f.isDirectory)
{
this.iterateFiles(f);
}
else
{
this.fileList.push(f);
}
}
}
Posted by cantrell at July 13, 2009 9:31 AM
Comments
Hi Christian,
Thanks for sharing, was looking for something like this :)
Cheers, Sid
Posted by: Sidney de Koning at July 14, 2009 5:38 AM