From: Timothy Hunter Date: 2006-10-22T05:40:56+09:00 Subject: Re: search file in a directory Li Chen wrote: > Hi folks, > > Which built-in method is used to search a file in a directory and all > its children directory? > > Thanks, > > Li > > Use Find.find to traverse a directory and subdirectories: timothyhunter$ ri Find ------------------------------------------------------------ Class: Find The Find module supports the top-down traversal of a set of file paths. For example, to total the size of all files under your home directory, ignoring anything in a "dot" directory (e.g. $HOME/.ssh): require 'find' total_size = 0 Find.find(ENV["HOME"]) do |path| if FileTest.directory?(path) if File.basename(path)[0] == ?. Find.prune # Don't look any further into this directory. else next end else total_size += FileTest.size(path) end end ------------------------------------------------------------------------ Instance methods: find, prune