saintex has asked for the wisdom of the Perl Monks concerning the following question:
---------------------------- Why this control fails?opendir OF, $oldFolder or die "\nCannot open dir $oldFolder: $!\n"; while ( my $name=readdir OF) { next if $name =~ /^\./ ; next if -f "$oldFolder/$name"; print $name; print "\n"; } closedir OF;
the control on ".",".." is correct; but it is always a directory, also when $name is a file. In that context also "-d $name" returns true also when it is a file not directorywhile (my $name=readdir OF) { next if ( ($name =~ /^\./ )||(-f $name) ); #must print only directories print $name; print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: check if it is a file or directory
by jwkrahn (Abbot) on Feb 26, 2010 at 14:58 UTC | |
by saintex (Scribe) on Feb 26, 2010 at 15:11 UTC | |
|
Re: check if it is a file or directory
by toolic (Bishop) on Feb 26, 2010 at 15:00 UTC | |
by saintex (Scribe) on Feb 26, 2010 at 15:18 UTC | |
by toolic (Bishop) on Feb 26, 2010 at 15:54 UTC | |
by saintex (Scribe) on Feb 26, 2010 at 16:06 UTC | |
|
Re: check if it is a file or directory
by Khen1950fx (Canon) on Feb 27, 2010 at 00:26 UTC | |
by toolic (Bishop) on Feb 27, 2010 at 01:52 UTC | |
by saintex (Scribe) on Feb 27, 2010 at 07:22 UTC | |
by Khen1950fx (Canon) on Feb 27, 2010 at 11:16 UTC |