?
Solved

Show the last made file!

Posted on 1999-07-19
6
Medium Priority
?
229 Views
Last Modified: 2010-03-04
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

0
Comment
Question by:mmcw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:mmcw
ID: 1214248
Sorry the 4..html has to be 4.html
0
 

Author Comment

by:mmcw
ID: 1214249
The file 4.html contains html.
When I start this script the HTML code must be send to the browser.
0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 1214250
# 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mmcw
ID: 1214251
How do I make a little script that reads the highest number and writes it to screen
0
 
LVL 5

Expert Comment

by:prakashk021799
ID: 1214252
> 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
 
LVL 1

Accepted Solution

by:
LostMyBrain earned 200 total points
ID: 1214253
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question