废话不多说,直接上代码
输出效果
[struts2]
|--freemarker-2.3.8.jar
|--ognl-2.6.11.jar
|--sitemesh-2.3.jar
|--struts2-core-2.0.11.jar
|--struts2-sitemesh-plugin-2.0.11.jar
|--xwork-2.0.4.jar
[tomcat5]
|--catalina-optional.jar
|--catalina.jar
|--jasper-compiler-jdt.jar
|--jasper-compiler.jar
|--jasper-runtime.jar
|--jsp-api.jar
|--jstl.jar
|--naming-factory-dbcp.jar
|--naming-factory.jar
|--naming-resources.jar
实现类似功能还可以模拟shell脚本写法
def get_file_list(path)
Dir.entries(path).each do |sub|
if sub != '.' && sub != '..'
if File.directory?("#{path}/#{sub}")
puts "[#{sub}]"
get_file_list("#{path}/#{sub}")
else
puts " |--#{sub}"
end
end
end
end
get_file_list('C:/lib/thirdpart/')
输出效果
[struts2]
|--freemarker-2.3.8.jar
|--ognl-2.6.11.jar
|--sitemesh-2.3.jar
|--struts2-core-2.0.11.jar
|--struts2-sitemesh-plugin-2.0.11.jar
|--xwork-2.0.4.jar
[tomcat5]
|--catalina-optional.jar
|--catalina.jar
|--jasper-compiler-jdt.jar
|--jasper-compiler.jar
|--jasper-runtime.jar
|--jsp-api.jar
|--jstl.jar
|--naming-factory-dbcp.jar
|--naming-factory.jar
|--naming-resources.jar
实现类似功能还可以模拟shell脚本写法
puts Dir["#{path}/**/*"]