开发者

Return link to the newest file on server with directory listing?

I want make an irssi script which will notice of new files on server, but firstly I need a script in Perl which will return the newest file on the server (apache 2.2.16 with directory listing) and after the 开发者_如何学Cnext script runs if there is no newer file then previous returns null or if there is a new file on the server return the link to that file. Thanks for any help.


  • Remember the script's start time in a variable $start_time

    You will need to store "last run time" in some persistent way (cache, file, persistent session data, database/DBM file) later on.

  • Have the script generate the list of files you want (using glob() if it's just files in a given directory, or File::Find if it's recursive in a directory structure

  • For each file, find its creation or modification (whichever one you want) timestamp via stat call

  • Find the newest file using stat data. If you used glob to list files, do it by scanning the list; if File::Find, just do it as part of callback memorizing the "latest seen so far" file

  • Retrieve "last run time" persistent data

  • If the last file found is later than "last run time" , return link to that file. if not, return null

  • Save the start time ($start_time) of the script as a new value of "last run time" to wherever you chose to tore it.


UPDATE

If the list of files is NOT local (e.g. on a web server), you need to replace the glob step to list the files (and stat for timestamps) with scraping of the appropriate HTML page containing directory listing (using for example WWW::Mechanize to retrieve the page and HTML::Twig or HTML::Parser to parse the HTML and retrieve the filenames and timestamps. There are also modules specifically for reading contents of HTML tables and I wouldn't be surprised if CPAN has a module to parse specifically Apaches file listing HTML.


UPDATE2

Looks like my hunch was right and there's a possible module to parse the HTML output from mod_autoindex: File::Listing::apache (part of libwww-perl distribution)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜