[erlang-questions] Best way to check if a given directory is empty (or not)?

Miles Fidelman mfidelman@REDACTED
Tue Mar 13 22:39:49 CET 2012


Richard O'Keefe wrote:
>
>
> If you just want to know whether the directory is *empty* or not, it's simple and tolerably
> fast at the C level:
>
> 	is_empty = 1;
> 	dirp = opendir("the directory");
> 	while ((entry = readdir(dirp)) != 0) {
> 	   if (0 != strcmp(entry->d_name, ".")
>              &&  0 != strcmp(entry->d_name, "..")
> 	   ) {
> 	      is_empty = 0;
>                break;
> 	   }
> 	}
> 	closedir(dirp);
>
> The OP's problem is that the Erlang libraries have nothing that mirrors
> this interface exactly, only things to give you the result of a complete
> scan.
>
>
Of course you can compile a tiny piece of C code and invoke it via an 
erlang port. :-)


-- 
In theory, there is no difference between theory and practice.
In practice, there is.   .... Yogi Berra





More information about the erlang-questions mailing list