Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: File::Find help

by Corion (Patriarch)
on Dec 02, 2017 at 09:48 UTC ( [id://1204708]=note: print w/replies, xml ) Need Help??


in reply to File::Find help

In your code, you are checking whether you have a file (-f). Maybe you want to do something there if you have a directory (-d)?

Note that you get the directory likely before all the files, so you might need to remember that you want to unlink rmdir a directory after you've successfully moved all the files.

Update Laurent_R noted the difference between unlink and rmdir.

Replies are listed 'Best First'.
Re^2: File::Find help
by colox (Sexton) on Dec 02, 2017 at 09:53 UTC

    Hi, Thank you for the reply. My dilemma is that the file (-f) could be way under multiple subdirectories. How can I effectively capture those so I can pass that to a variable to later do the unlink?

      Whenever you find a directory, remember it to be deleted afterwards?

      my @to_be_deleted; File::Find( ..., sub { if( -d $File::Find::name ) { print "'$File::Find::name' should be deleted later\n"; # push @to_be_deleted, $File::Find::name; }; }; rmdir @to_be_deleted; # boom

        great thanks much!... Follow-up to this, I hope you could also help me below: How about using Find::File to copy the subfolder + filename to another folder. Like: DIR_A/SUB_A/FILE_A ----> DIR_B/SUB_A/FILE_A Appreciate much your inputs.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1204708]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-24 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found