#! /usr/local/bin/perl # -------------------------------------------------------------- # # 指定したディレクトリ中のファイル一覧をRSSにするCGI # # -------------------------------------------------------------- # # 必要なモジュール # # XML::RSS # # ない場合は、RSS.pmをCPANから入手して ./XML/RSS/ に格納すればOK # # -------------------------------------------------------------- # # ▼設定 # -------------------------------------------------------------- # # リスト表示する対象のディレクトリ: my $targetDirectory = "./"; # そのディレクトリが対応するURL: my $targetURL = "http://www.example.com/hogehoge/; # RSSファイル化先: my $rssfilename = "filelist.xml"; # -------------------------------------------------------------- # unshift( @INC, "." ); use strict; use warnings; use XML::RSS; # ディレクトリのファイル一覧を得る opendir( DIRECTORY, $targetDirectory ); my @filelist = readdir( DIRECTORY ); closedir( DIRECTORY ); splice( @filelist, 0, 2 ); # 作成日時の文字列を作る my ($sec,$min,$hour,$day,$mon,$year); ($sec,$min,$hour,$day,$mon,$year,undef,undef,undef) = localtime(time); $year += 1900; $mon = &make2keta($mon+1); $day = &make2keta($day); $hour = &make2keta($hour); $min = &make2keta($min); $sec = &make2keta($sec); my $nowdate = "$year-$mon-$day" . "T" . "$hour:$min:$sec+09:00"; # RSS1.0を生成する my $rss = new XML::RSS( version => '1.0' ); $rss->channel( title => "FILE LIST : $targetURL", link => "$targetURL", description => "Files of $targetURL", dc => { date => $nowdate, language => 'ja', }, ); foreach my $file ( @filelist ) { $rss->add_item( title => "$file", link => "$targetURL$file", ); } # そのまま画面に出力したい場合: #print "Content-type: application/rdf+xml\n\n"; #print $rss->as_string; # ファイルに出力したい場合: print "Content-type: text/html\n\n"; $rss->save($rssfilename); print qq|