Show the last made file!

HEllo,

I have a directory with contains a lot of files.
The file are called:

1.html
2.html
3.html

etc.

When using a script called news a new file will be made.
For example now 4..html will be made.

What I now need is a little script taht load teh last file in this directory.
So When the file 4.html is last made, the script has to load this file
when this scripts is started!

Is this possible?

greetings Michel

mmcwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mmcwAuthor Commented:
Sorry the 4..html has to be 4.html
0
mmcwAuthor Commented:
The file 4.html contains html.
When I start this script the HTML code must be send to the browser.
0
prakashk021799Commented:
# The following code picks up the file which has the highest number prefix
# Also assuming that we have changed to the directory where the files reside

$file_to_display = (sort {$b <=> $a} glob "[0-9]*.html")[0];

# display the file to the browser
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

mmcwAuthor Commented:
How do I make a little script that reads the highest number and writes it to screen
0
prakashk021799Commented:
> How do I make a little script that reads the highest number and writes it to screen

OK. Here it is:

#!/usr/local/bin/perl

# change to the appropriate directory
chdir "/direcotry/where/html/files/reside" or die "can't chdir because $!\n";
# what is the latest file?
$latest_file = (sort {$b <=> $a} glob "[0-9]*.html")[0];

# open the file and display it

print "Content-Type: text/html\n\n";  # we are writing to a browser
open LATEST, "<$latest_file" or die "can't open $latest_file because $!\n";
while (<LATEST>) {
    print;
}
close LATEST;
0
LostMyBrainCommented:
Hi,

are you using PC / Unix?

If you are using unix you can implement it in a very little shell script:

>> cd <dir>
>> ls *.html | sort -n|tail -1

bye.
     

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.