473,394 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

need to get the newest and oldest files created

4
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
Nov 22 '06 #1
7 5747
GunnarH
83
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?
Nov 22 '06 #2
florin
4
u want a piece of the code, cause the whole thing is around 600+ lines of code?
Nov 22 '06 #3
GunnarH
83
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.
Nov 22 '06 #4
florin
4
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);

}
Nov 22 '06 #5
GunnarH
83
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:
Expand|Select|Wrap|Line Numbers
  1. use File::Find;
  2.  
  3. sub lastmodifiedfile {
  4.     my $dir = shift;
  5.     -d $dir or die "'$dir' is not a directory\n";
  6.     my %files;
  7.     File::Find::find (
  8.         sub {
  9.             my $name = $File::Find::name;
  10.             $files{$name} = (stat $name)[9] if -f $name;
  11.         }, $dir
  12.     );
  13.     ( sort { $files{$a} <=> $files{$b} } keys %files )[-1];
  14. }
  15.  
  16. print lastmodifiedfile('/some/directory');
HTH
Nov 22 '06 #6
florin
4
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
Nov 22 '06 #7
GunnarH
83
they don't give me any errors, i just broke it down in pieces.
I was talking about the prototypes.
Expand|Select|Wrap|Line Numbers
  1. sub numberofdir() {
  2. ---------------^^
They prevent you from passing arguments to the subs.
Nov 22 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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
19
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...
6
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
12
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...
20
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...
2
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...
2
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...
4
MindBender77
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
jinu1996
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...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.