profx
ill never 4get watsisname
Hi,
I am trying to develop a perl script that lists the content of a directory for a website. I have got it to list fine but the files dont seem to be sorted at all. How do i sort by date or name?
here is what i have so far. It lists directorys and their immediate contents. Folders are listed first
any help appreciated!!
I am trying to develop a perl script that lists the content of a directory for a website. I have got it to list fine but the files dont seem to be sorted at all. How do i sort by date or name?
here is what i have so far. It lists directorys and their immediate contents. Folders are listed first
Code:
sub mainlist {
opendir(DIR, ".");
@listing = readdir(DIR);
foreach $list (@listing) {
$stat = $list;
stat($stat);
if (-d _) {
if ($list ne "." && $list ne ".."{
print "$list";
&subdir;
print "";
print "\n";
}
}
}
closedir(DIR);
}
sub subdir {
chdir($list);
opendir(SUBDIR, ".");
@sub_listing = readdir(SUBDIR);
foreach $sub_list (@sub_listing) {
$sub_stat = $sub_list;
stat($sub_stat);
if (-d _) {#if a directory list first with bullet point
print "";
print " $sub_list " if $sub_list ne "." && $sub_list ne "..";
print "";
}
}
foreach $sub_list (@sub_listing) {
$sub_stat = $sub_list;
stat($sub_stat);
if (-f _) {#if a file list second
print "";
print " $sub_list " if $sub_list ne ".htaccess";
print "";
}
}
$back = "..";
chdir($back);
closedir(SUBDIR);
}
any help appreciated!!