hi, i have been working on a project that my brother gave me, im supposed to get the statistics of a directory and print them out in a html format, i have completed most of the requirements, but i still have a few problems
1. i need to get the newest and oldest files created (ex. the date)
2. i need to put it into a gooey, i guess he doesn't want to use apache, so have it on the desktop
if u have any ideas on how to do this i would greatly appreciate your help, thanks
7 5747
i have completed most of the requirements
Good. Show us the code you have, and somebody may be able to give you a hand.
2. i need to put it into a gooey
What's a gooey?
u want a piece of the code, cause the whole thing is around 600+ lines of code?
u want a piece of the code, cause the whole thing is around 600+ lines of code?
Yes, please. :)
Show at least how you grab the contents of the directory.
ok, ah these are the subroutines, what i did i broke everything down in pieces that way it would be easier for me to work with them and once one subroutine worked i left it alone and focused on the other part here are some subrotines. and if this isn't good i'll just print out the whole file, or code
#This gets how many directories i have
sub numberofdir() {
my $key = shift;
my $handle;
my $line;
my $file;
my $count;
opendir($handle, $key) or return;
while($line = readdir($handle)) {
if (open($file, "$key\\$line")) {
close($file);
}elsif($line ne "." && $line ne "..") {
$count++;
$count +=numberofdir("$key\\$line");
}
}
closedir($handle);
return $count;
}
# number of files in all directories
sub numfiles() {
my $key = shift;
my $handle;
my $line;
my $count;
my $file;
opendir($handle, $key) or return;
while($line = readdir($handle)) {
if(open($file, "$key\\$line")) {
$count++;
close($file);
}elsif($line ne "." && $line ne "..") {
numfiles("$key\\$line");
}
}
$filesinalldir{"$key\\$line"} = $count;
closedir($handle);
}
#this gets the smallest directory size
sub smallfilecount() {
my @filecount;
$filecount[0] = 30;
my $keys;
foreach $keys ( keys %filesinalldir){
if ($filesinalldir{$keys} < $filecount[0]) {
$filecount[0] = $filesinalldir{$keys};
$filecount[1] = $keys;
}
}
return @filecount;
}
sub largefilecount() {
my @filecount;
$filecount[0] = 30;
my $keys;
foreach $keys ( keys %filesinalldir){
if ($filesinalldir{$keys} > $filecount[0]) {
$filecount[0] = $filesinalldir{$keys};
$filecount[1] = $keys;
}
}
return @filecount;
}
#gets the sizes of the dir by adding all the files together
sub sizeofdir() {
my $key = shift;
my $file;
my $line;
my $handle;
my $filesize;
my @sizefile;
my $sum;
my $keys;
opendir($handle, $key) or return;
while($line = readdir($handle)) {
if(open($file, "$key\\$line")) {
$filesize = -s("$key\\$line");
push @sizefile, $filesize;
close($file);
}elsif ($line ne "." && $line ne "..") {
sizeofdir("$key\\$line");
}
}
foreach $keys ( @sizefile ) {
$sum += $keys;
}
$dirsize{$key} = $sum;
closedir($handle);
}
#gets the sizes of the dir by adding all the files together
sub sizeofdir() {
my $key = shift;
my $file;
my $line;
my $handle;
my $filesize;
my @sizefile;
my $sum;
my $keys;
opendir($handle, $key) or return;
while($line = readdir($handle)) {
if(open($file, "$key\\$line")) {
$filesize = -s("$key\\$line");
push @sizefile, $filesize;
close($file);
}elsif ($line ne "." && $line ne "..") {
sizeofdir("$key\\$line");
}
}
foreach $keys ( @sizefile ) {
$sum += $keys;
}
$dirsize{$key} = $sum;
closedir($handle);
}
Why the prototypes? Those subs don't do anything but giving you fatal errors, do they?
Anyway, there are modules to traverse directory trees, e.g. File::Find. This example returns the name of the last modified file: - use File::Find;
-
-
sub lastmodifiedfile {
-
my $dir = shift;
-
-d $dir or die "'$dir' is not a directory\n";
-
my %files;
-
File::Find::find (
-
sub {
-
my $name = $File::Find::name;
-
$files{$name} = (stat $name)[9] if -f $name;
-
}, $dir
-
);
-
( sort { $files{$a} <=> $files{$b} } keys %files )[-1];
-
}
-
-
print lastmodifiedfile('/some/directory');
HTH
they don't give me any errors, i just broke it down in pieces. But thanks for the help im gonna put it in my script and see how it goes, thanks again
they don't give me any errors, i just broke it down in pieces.
I was talking about the prototypes. - sub numberofdir() {
-
---------------^^
They prevent you from passing arguments to the subs.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bill H |
last post by:
Ok, I haven't passed MYSQL 101 yet and something I thought would be a
piece of cake has be stumped (it is almost 1a.m. thought ;)).
MYSQL: 3.23
TABLE:
file_id
member_id
file_name
|
by: ern |
last post by:
I need a FIFO queue of size 20, to keep track of a running average.
Once the queue is full with 20 values, I want to take the sum/20 =
AVERAGE. Then when a new value comes in, I want:
(Old Sum...
|
by: daveyand |
last post by:
Hey Guys,
I've stumped.
I created a function that does various things to select boxes.
Namely
Get All selected indexes,
populate array with these values
|
by: weeodett |
last post by:
Is there a way to automate the deletion of the oldest rows in a transaction log file when the file reaches a certain number of rows? Currently, we are simply deleting the oldest rows manually every...
|
by: mike |
last post by:
I help manage a large web site, one that has over
600 html pages... It's a reference site for ham radio
folks and as an example, one page indexes over
1.8 gb of on-line PDF documents.
The site...
|
by: pob |
last post by:
I was all happy because thru some tutelage of others I created this
array to find the newest file in a directory. However, I then
realized its great that I now know the latest file, but I need to...
|
by: Kidan |
last post by:
I built a small application that took export files from a sales
application, and transformed them into the format necessary for
importing by an accounting application. Both the Sales and the...
|
by: MindBender77 |
last post by:
Hello All,
I'm trying to find the newest file in a directory via the datetime created. Finally, I'm trying to use that newest timestamp to inform the user of this information in a msgbox.
I've...
|
by: |
last post by:
I'd like to be able to get the path to the oldest folder in whatever directory I'm currently in. Is there a simple way to go about this? I'd like it to run on both OS X and Windows XP. I found...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |