Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^7: dir handle

by RichardK (Vicar)
on May 27, 2014 at 12:25 UTC ( #1087523=note: print w/ replies, xml ) Need Help??


in reply to Re^6: dir handle
in thread dir handle

If you just want a list of the files in a directory then it's easier to just use glob

Also note that the files in a directory are not ordered, so any list will be in a random order unless you sort it.

Your code could then look something like this :-

use File::Basename; my @files = glob('/path/to/files/*'); foreach my $file (@files) { my $name = basename($file); if (! -x "/new_path/$name") { # copy file here } }

Have a look at the help for File::Basename or better yet File::Spec for functions to safely handle paths & filenames


Comment on Re^7: dir handle
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2015-07-07 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls