Deleting empty sub directories with File::Find 
Author Message
 Deleting empty sub directories with File::Find

Hi,

Was going to use File::Find for this but when I run it and print the
current directory for each call it doesn't actually seem to go into a
directory if the directory is empty. I assume i'm not missing anything
in the usage of File::Find as it looks like now I'll have to use
File::Find to clean up the files and then write a small recursive
routine to do post clean subdirectory removal.

Si



Sat, 15 Oct 2005 23:18:21 GMT  
 Deleting empty sub directories with File::Find

Quote:

> Was going to use File::Find for this but when I run it and print the
> current directory for each call it doesn't actually seem to go into a
> directory if the directory is empty.

It does not.

Quote:
> I assume i'm not missing anything in the usage of File::Find

Isn't that rather immodest?

In the File::Find callback $_ contains the leafname of the thing under
consideration and the cwd is set to the directory containing the thing
under consideration.  So the callback will never be called with a cwd
equal to an empty directory.

Quote:
> as it looks like now I'll have to use
> File::Find to clean up the files and then write a small recursive
> routine to do post clean subdirectory removal.

No.  Just make the callback sub { rmdir }.

This newsgroup does not exist (see FAQ).  Please do not start threads
here.



Sun, 16 Oct 2005 21:07:40 GMT  
 Deleting empty sub directories with File::Find
My email to you go bounced so I'm forced to respond here, sorry.

Apologies for the posting mixup, I even had trouble tracking down the
post
myself, such is life without direct newsgroup access. Google seems to
think it's fine to have a page that says "post a message to
comp.lang.perl" but I'd wager thats down to the generic nature of the
code
behind the pages.

Quote:
>> I assume i'm not missing anything in the usage of File::Find
>Isn't that rather immodest?

Odd, here was me thinking the comment implied maybe I hadn't read the
documentation thoroughly enough or maybe misinterpreted something. I
guess
thats the problem with the written word; it's easy to misinterpret ;-)
(smileys help :-) )

Anyway thanks for the advice, at the end of the day I didn't
appreciate
that it doesn't call wanted() blindly and on reflection I guess it's
obvious now that there is no reason it should call wanted from within
an
empty sub-directory

Ta

Si
PS: I notice a number of your entries in comp.lang.perl with the
comment about it not being a valid group (oh and for the newbies it
might be worth adding a link to the FAQ you mention), I'm surprised
no-one has told Google to sort it out?



Mon, 24 Oct 2005 19:48:21 GMT  
 Deleting empty sub directories with File::Find


...

Quote:
>> I assume i'm not missing anything in the usage of File::Find
> Isn't that rather immodest?

Hubris is a virtue B^)

--
Dodger



Tue, 25 Oct 2005 19:12:04 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. File::Find without desending into sub directories

2. Deleting a non empty directory

3. Delete empty directories

4. Find in sub-directories

5. Empty contents of a file without deleting it

6. Deleting Empty Files

7. Archive::Tar - tar a directory and sub directories

8. Finding sub name from sub pointer

9. Renaming all Files in a Directory and Sub...

10. Efficiently searching for a file in large sub directories

11. deleting only certain files in directory.

12. deleting all files in a directory

 

 
Powered by phpBB® Forum Software