[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSDirectoryEnumerator
From: |
Enrico Sersale |
Subject: |
Re: NSDirectoryEnumerator |
Date: |
Fri, 01 Oct 2004 20:49:38 +0300 |
On 2004-10-01 16:52:07 +0300 Alexander Malmberg <address@hidden> wrote:
Alexander Malmberg wrote:
Enrico Sersale wrote:
On 2004-09-30 21:42:44 +0300 Enrico Sersale <address@hidden> wrote:
Today, only to test how much time this keeps, I've tryed to create a
NSArray with all the directories on my disk.
The code is very simple, something like this:
[snip]
Could you make the source for this available somewhere?
To clarify, I mean the exact source of the tool(/whatever) that shows this
problem. It's always safest to debug the exact code, and it saves me from
having to write a test tool myself. :)
- Alexander Malmberg
Here it is.
It builds on GNUstep and on OSX without changes.
It writes to a file so we can avoid to think at NSMutableArray problems.
On my linux I get a file with 3500 lines, while "find / -type d" creates 55858
entries.
On OSX: if I build the tool with Xcode, the output is equal to "find / -type d"; if I
build it with GNUstep (gnu-gnu-gnu), it doesn't exit anymore from the while loop, fulling the disk.
It seems that it endless restarts from the first directory found in "/" (but all the
directories are found).
Unfortunately I can't test it on an other linux box.
#include <Foundation/Foundation.h>
static NSString *outpath = @"/home/enrico/enumerator.out"; // put here your path
int main(int argc, char** argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:
@"/"];
NSFileHandle *handle = [NSFileHandle fileHandleForWritingAtPath: outpath];
NSStringEncoding encoding = [NSString defaultCStringEncoding];
NSString *path;
while ((path = [enumerator nextObject])) {
if ([[enumerator fileAttributes] fileType] == NSFileTypeDirectory) {
path = [path stringByAppendingString: @"\n"];
[handle writeData: [path dataUsingEncoding: encoding]];
}
}
[handle closeFile];
[pool release];
return 0;
}