From: Scott Barron Date: 2006-10-23T05:45:37+09:00 Subject: Re: about file format ------=_Part_97769_24106391.1161549933698 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/22/06, Li Chen wrote: > > > > Directory of C:\Ruby > > > > 10/15/2006 18:21 34 OTI-4.001 > > 1 File(s) 34 bytes > > 0 Dir(s) 19,644,063,744 bytes free > > > > C:\bonak\Ruby>irb > > irb(main):001:0> File.file?('OTI-4.001') > > => true > > irb(main):002:0> > > > > Works here too .. so I am not sure why yours is not > > working. Did you try again? I have managed to get irb > > confused before and once I restarted things worked well. > > > > eb > > Hi EB, > > I figure out why it doesn't work: irb only looks for the file name in > current directory. I try on both linux and xp. > But the files I want to search are in a different drive under XP. > Actually this question comes from the following script1 and script2: > > ########### script1--It works perfect. > file_number=0 > path="I:\\Common\\Gao\\Notebooks\\Flow\\OT1\\OTI-4" > > Dir.foreach(path) do |file_name| > > if file_name=~/(\w+|d+).(\d{3,})/ > puts file_name > file_number+=1 > end > end > > puts > puts 'Files',path > puts 'File number',file_number > > ############Screen ouptut > C:\Ruby\self>dir5.rb > OTI-4.001 > ... > OTI-4.025 > OTI-4.026 > > Files > I:\Common\Gao\Notebooks\Flow\OT1\OTI-4 > File number > 26 > > ####script2--Doesn't work > > file_number=0 > path="I:\\Common\\Gao\\Notebooks\\Flow\\OT1\\OTI-4" > > Dir.foreach(path) do |file_name| > > if File.file?(file_name) > puts file_name > puts File.size(file_name) > file_number+=1 > end > end > > puts > puts 'Files',path > puts 'File number',file_number > > ##screen output > > C:\Ruby\self>dir5.rb > > Files > I:\Common\Gao\Notebooks\Flow\OT1\OTI-4 > File number > 0 > > But right now I just don't know how to make script 2 work. > > Li As was said in another thread, you need to assemble the full path to the file. Dir.foreach(path) do |file_name| if File.file?(File.join(path, file_name)) # ... end end -Scott ------=_Part_97769_24106391.1161549933698--