From: Josh Charles Date: 2005-09-08T06:28:57+09:00 Subject: Re: FileTest.directory?( x ) weird behavior Excellent. Thanks for the help. I should have known better... Josh On 9/7/05, Robert Klemme wrote: > Josh Charles wrote: > > I have a bit of code I'm working on where I need to seperate the > > directories from the files. Currently, it's processing the first > > three properly and skipping the rest. > > > > I'm running this on windows. > > > > Here is the code: > > > > def GetFolders > > rtn = "" > > Dir.foreach( @userFilePath ) do |x| > > if FileTest.directory?( x ) > > rtn += "" unless x <= ".." > > end > > end > > return rtn > > end > > > > def GetFiles > > rtn = "" > > Dir.foreach( @userFilePath ) do |x| > > rtn += "" unless > > FileTest.directory?( x ) > > end > > return rtn > > end > > > > It gives the output of: > > > > > > > > > > > > > > > > > > > > > > > > > > > > The actual directory contains: > > > > . > > .. > > 404.html > > 500.html > > asdf > > asdnt.txt > > silk > > test > > thingy.html > > 4 File(s) 567 bytes > > 5 Dir(s) 22,350,041,088 bytes free > > > > I'm still learning ruby, so I've probably written something > > incorrectly... > > You're testing relative file names only while you want absolute file names: > > def GetFolders > rtn = "" > Dir.foreach( @userFilePath ) do |x| > if FileTest.directory?( File.join( @userFilePath, x ) ) > rtn << "" unless x <= ".." > end > end > return rtn > end > > Kind regards > > robert > > >