From: Kyle Schmitt Date: 2008-01-12T00:19:32+09:00 Subject: Counting the files in a directory.... I'm writing some scripts to help manage a mail scanner used at my work. Being a mail scanner, it's got huuuuUUUge quarantine directories. Now, I know I can do something along the lines of: Dir.open("/foo").collect.length-2 #if you're wondering, the -2 is to ignore . and .. to get a count of what's in a directory, but the problem there is, it's rather slow when you run that in a directory with a few thousand files on a server under a severe (4.5>average_load>2) load. After perusing the Dir, Find and Stat classes, I haven't seen a better way. I thought that perhaps there was some sort of system call, at least in Real OSes™ (Linux, *BSD, Unix, etc), that would return the number of files inside of a directory. Something that would hopefully return in a 1/4th or 1/8th a second, rather than in 4 or 8 (or 20...) seconds. Any clues? Thanks, Kyle