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

Zabrane Mickael zabrane3@REDACTED
Tue Mar 13 09:24:25 CET 2012


Yep. Any other advices/hints?

Regards,
Zabrane

On Mar 13, 2012, at 9:03 AM, Steve Strong wrote:

> Yeah, if there are other processes (erlang or os) then that would be a problem :) - obviously easy to recreate the directory if it did get deleted but you would have that time when it wasn't there.
> 
> Sent from my iPhone
> 
> On 13 Mar 2012, at 08:49, Zabrane Mickael <zabrane3@REDACTED> wrote:
> 
>> I already tried the file:del_dir/1 trick.
>> 
>> The only downside is when this directory is really empty ... then it will be deleted.
>> My app will not work anymore as the existence of the directory is mandatory.
>> 
>> Regards,
>> Zabrane
>> 
>> 
>> On Mar 13, 2012, at 8:41 AM, Steve Strong wrote:
>> 
>>> Not a good solution if other apps are using the directory, but if it's just your app you could call file:del_dir() - if it's empty, it will return ok if not you'll get an {error,eexist} error.  No idea on the performance characteristics, but suspect it's pretty good...
>>> 
>>> -- 
>>> Steve Strong
>>> @srstrong
>>> 
>>> Sent with Sparrow
>>> 
>>> On Tuesday, 13 March 2012 at 07:09, Zabrane Mickael wrote:
>>> 
>>>> Hi guys,
>>>> 
>>>> I'd like to know if there's a good and portable method to check if a directory is empty (or not)?
>>>> In my case, the directory can contains huge number (more than 150K in average) of files if it is not empty.
>>>> 
>>>> I've tested the following working calls:
>>>> a. file:list_dir/1
>>>> b. filelib:wildcard/2
>>>> 
>>>> The problem with them is they both return a list of filenames.
>>>> I'd like to avoid getting this list back to be able to check if it's empty or not.
>>>> 
>>>> Advices please?
>>>> 
>>>> Regards
>>>> Zabrane
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>> 
>> 
>> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120313/9f040956/attachment.htm>


More information about the erlang-questions mailing list