Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: read directory

by choroba (Cardinal)
on Dec 20, 2017 at 15:32 UTC ( [id://1205912]=note: print w/replies, xml ) Need Help??


in reply to read directory

This has been asked many times. Even the documentation of readdir itself mentions the problem:
If you're planning to filetest the return values out of a readdir, you'd better prepend the directory in question.

Also, you should always check the return value of opendir. Moreover, use strict and warnings, they should tell you that $fh and $dh are different variables.

So, all of that together:

#!/usr/bin/perl use warnings; use strict; my $dir = 'C:/'; opendir my $dh, $dir or die $!; while (my $file = readdir $dh) { print "$file\n" if -d "$dir/$file"; } close $dh;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: read directory
by Anonymous Monk on Dec 20, 2017 at 15:49 UTC

    Why doesn't my if-statement work?

      OK, let's assume you start in "D:\Program Files" and run the script. It reads a filename from C:\, let's say temp. Your if tries to verify that the directory temp exists in the current directory, i.e. "D:\Program Files\temp" is a directory, which is false. My if, on the other hand, tries to verify that "C:\temp" is a directory, which is true.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Thanks for responding

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found