M626
Programmer
- Mar 13, 2002
- 299
I am using the following to output a file listing the contents of a directory. Is there anyway i can modify this to output by date created or date modifed?
#!perl
print "Content-type: text/plain\n\n";
# Configuration:
$internal_path = "r:/";
$list_directories = "true";
$list_files = "true";
$list_bytes_total = "true";
@Directory_Parent = $internal_path;
while (@Directory_Parent)
{
$directory = shift (@Directory_Parent);
opendir(DIR, $directory) || next;
while (defined($child = readdir(DIR)))
{
if ((-d "$directory/$child") && ($child ne ".") && ($child ne ".."))
{
push(@Directory_Parent, "$child");
if ($list_directories eq "true")
{ push (@Directory_List, "$child"); }
{ push (@File_List, "<br>"); }
}
if ((-f "$directory/$child") && ($list_files eq "true"))
{ push (@File_List, "$child"); }
{ push (@File_List, "<br>"); }
if ((-f "$directory/$child") && ($list_bytes_total eq "true"))
{
$filename = "$directory/$child";
$bytes = $bytes + (-s $filename);
}
}
closedir(DIR);
if ($bytes)
{
push (@Bytes, " $directory : $bytes");
$bytes = 0;
}
}
open(OUTFILE, "> C:/LIST.txt") or die "can't open outfile : $!\n";
# @Directory_List = sort { $a cmp $b } (@Directory_List);
# @File_List = sort { $a cmp $b } (@File_List);
print "Parent Directory Of:\n $internal_path\n\n";
$" = "\n";
if (@Directory_List)
{ print "Child Directories Found:\n @Directory_List\n\n"; }
if (@File_List)
{ print "Files Found:\n@File_List\n\n"; }
{ print OUTFILE "FileLIST:\n@File_List\n\n"; }
$" = " ";
exit;
#!perl
print "Content-type: text/plain\n\n";
# Configuration:
$internal_path = "r:/";
$list_directories = "true";
$list_files = "true";
$list_bytes_total = "true";
@Directory_Parent = $internal_path;
while (@Directory_Parent)
{
$directory = shift (@Directory_Parent);
opendir(DIR, $directory) || next;
while (defined($child = readdir(DIR)))
{
if ((-d "$directory/$child") && ($child ne ".") && ($child ne ".."))
{
push(@Directory_Parent, "$child");
if ($list_directories eq "true")
{ push (@Directory_List, "$child"); }
{ push (@File_List, "<br>"); }
}
if ((-f "$directory/$child") && ($list_files eq "true"))
{ push (@File_List, "$child"); }
{ push (@File_List, "<br>"); }
if ((-f "$directory/$child") && ($list_bytes_total eq "true"))
{
$filename = "$directory/$child";
$bytes = $bytes + (-s $filename);
}
}
closedir(DIR);
if ($bytes)
{
push (@Bytes, " $directory : $bytes");
$bytes = 0;
}
}
open(OUTFILE, "> C:/LIST.txt") or die "can't open outfile : $!\n";
# @Directory_List = sort { $a cmp $b } (@Directory_List);
# @File_List = sort { $a cmp $b } (@File_List);
print "Parent Directory Of:\n $internal_path\n\n";
$" = "\n";
if (@Directory_List)
{ print "Child Directories Found:\n @Directory_List\n\n"; }
if (@File_List)
{ print "Files Found:\n@File_List\n\n"; }
{ print OUTFILE "FileLIST:\n@File_List\n\n"; }
$" = " ";
exit;