Ruby 遍历目录

 require 'find'
 
 def fileWalk(path)
  Find.find(path) do |f|  
      type = "File" if File.file?(f)
      type  = "Dir " if File.directory?(f)
        if type != "File" && type != "Dir "
          type = "   ?"
        end
    puts "#{type}: #{f}"  
  end  
end

fileWalk('C:\Ruby\doc') #put whatever folder here

编程技巧