[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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

0
mmcw
Asked:
mmcw
  • 3
  • 2
1 Solution
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now