#!/usr/bin/env ruby ######################################################################## # rss_dir_list.rb - test command for Raggle exec: URLs # # by Paul Duncan # # # # Output an RSS feed describing the contents of a directory # # # # Note: This command can take quite a while large directories and/or # # slower machines. # ######################################################################## PATH = ARGV.shift || '.' class String def html_escape str = dup str.gsub!(/&/, '&') if str =~ /&/ str.gsub!(//, '>') if str =~ />/ str end end time_str = Time.now.to_s.html_escape puts <<-ENDHEADER Dir List: '#{File::basename(PATH)}' http://www.raggle.org/ Output of the following command<br> (last ran at #{time_str}): <pre> #$0 #{PATH.html_escape} </pre> ENDHEADER Dir["#{PATH}/*"].each { |path| next if path =~ /^\./ puts <<-ENDFILEHEADER #{File::basename(path)} file://#{path} ENDFILEHEADER # get file attributes desc = {} begin stat = File::stat(path) puts " #{stat.mtime.to_s}", ' ' puts ["Path: #{path}
", "Type: #{stat.ftype}
", "Modified: #{stat.mtime}
", "Size (in bytes): #{stat.size}
", "Permissions: #{'%05o' % stat.mode}
", "Owner: #{stat.uid}
"].join("\n").html_escape { 'MIME' => '-ib', 'Content' => '-b' }.each { |title, opts| IO::popen("file #{opts} #{path}") { |pipe| puts "#{title}: #{pipe.read}
".html_escape } } puts '
', '
' rescue puts "Error: #$!", ' ', ' ' end } puts <<-ENDFOOTER
ENDFOOTER