0 Replies - 1253 Views - Last Post: 26 November 2009 - 08:09 AM

#1 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Directory Walk

Posted 26 November 2009 - 08:09 AM

Description: I would recommend not using this on a large directory, or if you do, don't print all the information to the screen until the very end, to save some timeUses a built in function to recursively list the files and folders (and subfolders (and subfolders (and subfolders))) of a given path
 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:Rubydoc') #put whatever folder here


Is This A Good Question/Topic? 0
  • +

Page 1 of 1