Re: Recognize directories and files.

From: Mitchell Hulscher (unacceptable_at_gmail.com)
Date: 12/09/04


Date: 09 Dec 2004 19:32:31 GMT

Hey all,

I just took a look at the replies to my post, and I was glad
there were people that could help me to find an answer.
I must say I found the first reply kind of "rough", but I DID
manage to get my code working. So, thanks a lot.
I was wrong thinking that looking for a period would be my
solution just because I couldn't figure out the -d and -f
switches.
Also my English isn't at it's best so that's probably why I
mixed up 'colon' with 'period'.
Anyway, this is my new code:

#!C:\perl\bin\

use warnings;

print "Enter a full directory path to examine: ";

chomp($dir = <STDIN>);

$dir .= "\\" unless $dir =~ /\\+$/;

opendir(HANDLE, $dir) || die "Unable to open directory for
analysis: $!";

foreach (readdir(HANDLE)) {
   $path = $dir . $_;
   if (-d $path) {
      push(@dirs, $path);
   } elsif (-f $path) {
      push(@files, $path);
   }
}

sort(@files);
sort(@dirs);

print "\n\nDirectories:\n------------\n";

foreach (@dirs) {
   print "$_\n";
}

print "\n\nFiles:\n------\n";

foreach (@files) {
   print "$_\n";
}

#End of program.

I'm glad I got it working, and if anyone still has any comments
on this code, please let me know.
What is annoying, is that the arrays are empty at program load,
and Perl returns an error saying it cannot sort empty void.
Ofcourse, the arrays will be filled later, but I was wondering
if there was any way of preventing this "error".

Thanks in advance,
Mitch.

----------------------------------------------
Posted with NewsLeecher v2.0 RC2
 * Binary Usenet Leeching Made Easy
 * http://www.newsleecher.com/?usenet
----------------------------------------------



Relevant Pages

  • Re: SQLBulkOperations question
    ... The arrays are not of the same length. ... T> gives an error saying that duplicate values are being written though ... T> If the table does not have a primary key things go ok. ... T> BulkOps without the totla data being a multiple of the first array? ...
    (microsoft.public.data.odbc)
  • Re: Arrays.sort(s) caused an error
    ... The 2nd line has an error saying: ... found: void ... sort doesn't have a return value. ... Arrays are muttable, this allows the ...
    (comp.lang.java.gui)
  • Error due to large array?
    ... when i try to execute the following program i get an error saying: ... the system can not execute the specified program. ... smaller (all arrays less than about 5000), ...
    (comp.lang.fortran)