From: jreidthompson Date: 2008-01-15T23:57:12+09:00 Subject: Re: Counting the files in a directory.... Kyle Schmitt wrote: > > > I'll try and read more of the C stuff for handling files/directories > in unix. I can hold out hope for awhile. > > Thanks, > Kyle > You may have already gotten here.... What kind of times does this give? ( the first run will include the initial compilation time ) You can modify it to meet your needs ( if you have questions, just post back ) -- see man scandir you can setup a filter function to allow returning counts for specific file matches. As is, it returns a count for all files, visible and hidden. for rubyinline see: http://www.zenspider.com/ZSS/Products/RubyInline/ https://rubyforge.org/projects/rubyinline -----------snip dircount.rb-------------------------------- require 'inline' class DirCount inline do | builder | builder.include '' builder.include '' builder.c " int count() { struct dirent **namelist; int n; int count; count = n = scandir(\".\", &namelist, 0, 0); if (n < 0) perror(\"scandir\"); else { while(n--) { /* printf(\"%s\n\", namelist[n]->d_name);*/ free(namelist[n]); } free(namelist); } return (count); }" end end dc = DirCount.new() puts dc.count() -----------snip-------------------- -- View this message in context: http://www.nabble.com/Counting-the-files-in-a-directory....-tp14758608p14841411.html Sent from the ruby-talk mailing list archive at Nabble.com.