From: Alex Date: 2009-07-21T05:34:46+09:00 Subject: Re: Dir.entries showing . and .. , how come? On Mon, Jul 20, 2009 at 4:19 PM, David Masover wrote: > On Monday 20 July 2009 03:05:18 pm Mmcolli00 Mom wrote: >> Why is it that there are '.' and '..' in my output? > > Those are hidden directories on Unix, pointing to the current and parent > directory. I'm not sure why they're on Windows, too... > >> I want to create a >> list of all the files in this directory without showing the . and .. at >> the top of the list. What do you do for this? > > I'd do this:I > > #snippet > myfolder = "c:/myfolder" > > Dir.entries(myfolder).each do |filename| >  puts filename unless filename =~ /^\.\.?$/ > end > #end snippet > > You could do it other ways, too. I'm not sure which is faster. > > Of course, this might still not do what you want -- it's going to include > folders, too. If you just want files, you could do something like this: > > Dir.entries(myfolder).each do |filename| >  puts filename if File.file?(filename) > end > > I would just do something like this: Dir.entries(dir).reject{|entry| entry =~ /^\.{1,2}$/} But my regex-fu may be weak. Since it's only 2 possibilities, it might be simpler to just do this: Dir.entries(dir).reject{|entry| entry == "." || entry == ".."} That's really just semantics, though. Alex