Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / September 2006



Tip: Looking for answers? Try searching our database.

directoryContentsAtPath returns zero-sized array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Boris Schulz - 21 Sep 2006 23:12 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.