rc wrote:

Is there a way to make this single line wonder here get the exact count at once (like Finder's Get Info does) without having to enumerate the directory/recurse? If you send it a folder URL, it will only provide that folder's count, it will not include the count of any folders inside that folder, unless you recurse it with an enumerator...

dirPath = fn CFURLCopyFileSystemPath( dirURL, _kCFURLPOSIXPathStyle )
BeginCCode
totalItems = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:(NSString*)dirPath error:NULL] count];
endC
CFRelease(dirPath)

This counts files only. If directories should be included in the count, then change this line:
if ( !CFURLHasDirectoryPath( (CFURLRef)url ) ) count++;
to:
count++;

'---------------
include "ConsoleWindow"
compile as "Objective-C"

// options
begin enum
_kSkipsSubdirectoryDescendants = 1L << 0
_kSkipsPackageDescendants      = 1L << 1
_kSkipsHiddenFiles             = 1L << 2
end enum

BeginCDeclaration
UInt32 CFURLFilesInDirectory( CFURLRef inURL, UInt32 options );
EndC
BeginCFunction
UInt32 CFURLFilesInDirectory( CFURLRef inURL, UInt32 options )
{
     UInt32 count = 0;
     NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:(NSURL *)inURL
                                                           includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLIsDirectoryKey,nil]
                                                                              options:options
                                                                         errorHandler:nil];
     for ( NSURL *url in enumerator ) {
          if ( !CFURLHasDirectoryPath( (CFURLRef)url ) ) count++;
     }
     return count;
}
EndC
toolbox fn CFURLFilesInDirectory( CFURLRef inURL, UInt32 options ) = UInt32

dim as CFURLRef dirURL

if ( files$( _CFURLRefFolder, "Select slides folder",, @dirURL ) )
print fn CFURLFilesInDirectory( dirURL, _kSkipsHiddenFiles + _kSkipsSubdirectoryDescendants )
print fn CFURLFilesInDirectory( dirURL, _kSkipsHiddenFiles )
end if
'---------------

Bravo Whisky



--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@... To access the list archives, go to: http://freegroups.net/groups/futurebasic/