Sasaki wrote:
> hi guys,
>           How can i determine the file type?
> I have to do these actions:
> 
> 1. I have tor read all files from a directory and check them
> 2.after checking i have to read only the excel files.
> 
> I have tried with the code..
>     initial_dir = ["./upload_dir"]
>     for dir in initial_dir
>     Find.find(dir)do |path|
>      files_list << path
>      file_part= path.split('/')
>      file_type=file_part[1].split('.')
>        if(file_type[1]=='xls')
>          read the file
> 
>           end
>      end
> end
> 
> error is "Exception: Permission denied - ./upload_dir"
> probably, the code also try to process the "../" and "./"
> 
> So how can i check the file type.
> 
> please help me waiting for ur response
> 
> Sasaki

If you're trusting the file extension (which I see no problem with), and 
you're only dealing with files in the directory specified (no subdirs) 
you could do something like this:

Dir.entries('./upload_dir').each do |file|
  if file.split('.').last == 'xls'
    # process file
  end
end

HTH,
Chris

-- 
Posted via http://www.ruby-forum.com/.