Stripping the extensions off of a file

I'm building a program that goes thru a file structure, and it will find
the longest filename and biggest files.

Find.find(directory) do |f|
     file_sizes[File.size(f)]= f
     if File.file?(f)
         file_stripper = File.basename(f).delete(".jpg") #FIGURE OUT TO
STRIP THE ExTENSION

         file_length[f] = file_stripper
     end

   end

I got that part, but I can't seem to be able to strip the extension,
because I don't want to count the extensions part part of the length.

Can the delete method take regexep? WHat would the regexep for something
like anything after the "."?

thanks!

···

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

# Find.find(directory) do |f|
# file_sizes[File.size(f)]= f
# if File.file?(f)
# file_stripper = File.basename(f).delete(".jpg")
# #FIGURE OUT TO
# STRIP THE ExTENSION

get the extension, then pass it to #basename

botp@pc4all:~$ qri File.basename
--------------------------------------------------------- File::basename
     File.basename(file_name [, suffix] ) -> base_name

···

From: Feng Tien [mailto:pood.forums@gmail.com]
------------------------------------------------------------------------
     Returns the last component of the filename given in file_name,
     which must be formed using forward slashes (``/'') regardless of
     the separator used on the local file system. If suffix is given
     and present at the end of file_name, it is removed.

        File.basename("/home/gumby/work/ruby.rb") #=> "ruby.rb"
        File.basename("/home/gumby/work/ruby.rb", ".rb") #=> "ruby"

:~$ irb
~001:0> name="/home/botp/test.rb"
=> "/home/botp/test.rb"
~002:0> File.basename(name,File.extname(name))
=> "test"

kind regards -botp

great thanks! I didn't know the File library had that method.

···

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