Hello,
the following code compiles just fine, but the size of "fileArray" that
I get by using count is zero and more obviously, the code depending on
the array is never really called.
However, I know that there are "some" files in my homedirectory, which
is what I tested the code with.
Maybe someone can point out what I did wrong?
thanks in advance and greets, B.S.
My code:
- (NSMutableArray *) getFileList:(NSString *)initPath
{
NSMutableArray * resultArray;
NSString * fileName;
NSFileManager * fileManager = [NSFileManager defaultManager];
// the next line creates the zero-sized array
NSArray * fileArray = [fileManager
directoryContentsAtPath:initPath];
NSEnumerator * enumerator = [fileArray objectEnumerator];
while ((fileName = [enumerator nextObject])!=nil)
{
NSLog(@"entered loop with fileName: %s", fileName);
NSImage * testImage = [[NSImage alloc]
initWithContentsOfFile:fileName];
if(testImage != nil)
{
[resultArray addObject:fileName];
}
}
return resultArray;
}
matt neuburg - 22 Sep 2006 00:34 GMT
> Hello,
>
[quoted text clipped - 30 lines]
> return resultArray;
> }
What on earth could "never really called" mean? Either the code is
"called: (the log message appears) or it isn't. Which?
Anyway you're not giving sufficient information, since you do not show
how you are calling getFileList:. The value of initPath could be bogus.
I don't see any error-checking against that possibility...
Oh, and while I'm offering free criticism, you've got a memory leak. :)
m.

Signature
matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com
John C. Randolph - 22 Sep 2006 03:58 GMT
> Hello,
>
[quoted text clipped - 3 lines]
> However, I know that there are "some" files in my homedirectory, which
> is what I tested the code with.
NSFileManager isn't going to expand tildes in the string you hand it,
so did you pass it the full path to your home directory, or perhaps try
to use @"~"?
Try handing your method the string you get from NSHomeDirectory() or
NSHomeDirectoryForUser();
-jcr
Boris Schulz - 23 Sep 2006 17:40 GMT
... ah, well, I solved my problem...
somehow it helped to use "/Users/bs" instead of "/home/bs" :-)
Sometimes I forget that there are some significant differences to my
other unixes. I should probably really use the function that returns my
homedir.
Thanks anyway, guys!
greets, B.S.