473,593 Members | 2,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need to get the newest and oldest files created

4 New Member
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 5768
GunnarH
83 New Member
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 New Member
u want a piece of the code, cause the whole thing is around 600+ lines of code?
Nov 22 '06 #3
GunnarH
83 New Member
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 New Member
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\\$lin e")) {
close($file);
}elsif($line ne "." && $line ne "..") {
$count++;
$count +=numberofdir(" $key\\$line");
}
}
closedir($handl e);
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\\$lin e")) {
$count++;
close($file);
}elsif($line ne "." && $line ne "..") {
numfiles("$key\ \$line");
}
}
$filesinalldir{ "$key\\$lin e"} = $count;
closedir($handl e);
}

#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\\$lin e")) {
$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($handl e);

}
#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\\$lin e")) {
$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($handl e);

}
Nov 22 '06 #5
GunnarH
83 New Member
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 New Member
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 New Member
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
1495
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
6242
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 - oldest value + newest value)/20 = New Average Anybody know an efficient way to implement that? Is a queue even the best way? Thanks,
6
1749
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
2839
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 so often. But we would like to put something in place that will do this automatically. The reason for doing this is to ultimately improve the application's performance that writes the transactions to this file. When the file gets to be over about...
20
4250
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 is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
2
2073
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 know the name of the file. Unfortunately, I am only passing the date into the array. Do I need to create a m-d array ? If so how do I create a 2-d array where I do not know how many rows I will be looping thru ?
2
1540
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 accounting application are server applications. I built the conversion tool using .NET 1.1 on a WindowsXP box. It was deployed to a Win2k box. And for a while, it worked perfectly fine.
4
3450
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 tried using My.Computer.Filesystem.GetFileInfo and a few other snippets I've found on the web but, none quite produce the desired result. Each file in this directory has this format: FileName_MMddyyyy-hh.mm.ss.txt Any Help will be greatly...
0
954
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 this example at "http://trac.v2v.cc/browser/python-v2v/v2v/v2v.py?rev=python-v2v%2C37", but was curious if there's a better way to do this? def get_oldest_v2v_folder(): 404 ''' 405 returns the oldest folder in share_dir 406 407 ...
0
7936
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7874
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8227
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6646
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3853
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.