Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: readdir and recognizing difference between files and directories

by tirwhan (Abbot)
on Apr 07, 2010 at 15:07 UTC ( #833319=note: print w/replies, xml ) Need Help??


in reply to readdir and recognizing difference between files and directories

You're testing the files and directories as if they were in your current working directory, not the one you're examining. Here's a version that would work:

#!/usr/bin/perl use strict; use warnings; my $dir = "D:/test_dir"; opendir( DIR, $dir); my @file_list = readdir(DIR); closedir(DIR); print "Decision whether it is a file or a directory:\n"; foreach ( @file_list ) { if( (-d "$dir/$_") ) { print "directory: " . $_ . "\n"; } if( (-f "$dir/$_") ) { print "file: " . $_ . "\n"; } } print "\n\n"; print "Just print everything:\n"; foreach ( @file_list ) { print $_ . "\n"; }

All dogma is stupid.
  • Comment on Re: readdir and recognizing difference between files and directories
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://833319]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-08-21 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (325 votes). Check out past polls.

    Notices?