Skip to content

Instantly share code, notes, and snippets.

@masterkain
Forked from entropie/gist:186044
Created October 5, 2009 12:10
Show Gist options
  • Save masterkain/202070 to your computer and use it in GitHub Desktop.
Save masterkain/202070 to your computer and use it in GitHub Desktop.
def browse
root, dir = File.expand_path("."), request[:dir]
@lis = []
begin
path = root + "/" + dir
Dir.chdir(File.expand_path(path)) do
if Dir.pwd[0,root.length] == root then
files = Dir.glob("*")
files.each{ |x|
next unless File.directory?(x)
@lis << "<li class=\"directory collapsed\"><a href=\"#\" rel=\"#{dir}#{x}/\">#{x}</a></li>";
}
files.each{ |x|
next unless File.file?(x)
ext = File.extname(x)[1..-1]
@lis << "<li class=\"file ext_#{ext}\"><a href=\"#\" rel=\"#{dir}#{x}\">#{x}</a></li>"
}
else
@lis << "<li>You are way out of your league</li>"
end
end
rescue
@lis << "<li>Internal Error</li>"
end
@lis << "</ul>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment