[futurebasic] Re: [FB] Total items count for folder

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2013 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Thu, 27 Jun 2013 15:04:50 +0100
rc wrote:

> Thanks. No handy one liners for this I guess. :) 

Don't think so. For interest, here's an example of using the UNIX 'file' command. Could be used with NSTask or popen() to avoid pascal strings.
'---------------
include "ConsoleWindow"

local fn FileCountInDirectory( url as CFURLRef, recurse as Boolean )
'~'1
dim as Str255 s, cmd, reply
dim as CFStringRef path

path = fn CFURLCopyPath( url )
fn CFStringGetPascalString( path, @s, 256, _kCFStringEncodingMacRoman )
CFRelease( path )
cmd = "find " + s
if ( recurse == _false ) then cmd += " -depth 1"
cmd += " -type f | wc -l"
open "UNIX", 222, cmd
input #222, reply
close 222
end fn = val( reply )

dim as CFURLRef dirURL

if ( files$( _CFURLRefFolder, "Select slides folder",, @dirURL ) )
print fn FileCountInDirectory( dirURL, _true )
CFRelease( dirURL )
end if
'---------------