Re: Recognize directories and files.
From: Mitchell Hulscher (unacceptable_at_gmail.com)
Date: 12/09/04
- Next message: brian d foy: "Re: FAQ 4.22: How do I expand function calls in a string?"
- Previous message: Tintin: "Re: Using MIME::Lite for multipart message - trouble with string manipulation"
- In reply to: Paul Lalli: "Re: Recognize directories and files."
- Next in thread: Paul Lalli: "Re: Recognize directories and files."
- Reply: Paul Lalli: "Re: Recognize directories and files."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
----------------------------------------------
- Next message: brian d foy: "Re: FAQ 4.22: How do I expand function calls in a string?"
- Previous message: Tintin: "Re: Using MIME::Lite for multipart message - trouble with string manipulation"
- In reply to: Paul Lalli: "Re: Recognize directories and files."
- Next in thread: Paul Lalli: "Re: Recognize directories and files."
- Reply: Paul Lalli: "Re: Recognize directories and files."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|