Open files in other directories

Thank you very much. As a ruby noob I am still learning the built in

methods.

I didn't even think to use glob.

No worries - that's what this list is for :slight_smile:

It just hit me:

  campershash["#{textfilename.chop.chop.chop.chop}"] =

Try textfilename[0..-5] for a fixed size slice.

You're probably trying to remove the extension. Take a look at File
class methods: basename, extname, dirname etc. You can strip extension
by:
  base_name = textfilename.delete File.extname(textfilename)

Mehr, Assaph (Assaph) wrote:

Thank you very much. As a ruby noob I am still learning the built in
   

methods.

I didn't even think to use glob.
   
No worries - that's what this list is for :slight_smile:

It just hit me:

campershash["#{textfilename.chop.chop.chop.chop}"] =
     

Try textfilename[0..-5] for a fixed size slice.
   
You're probably trying to remove the extension. Take a look at File
class methods: basename, extname, dirname etc. You can strip extension
by:
base_name = textfilename.delete File.extname(textfilename)

Excellent. The multiple chops were a quick hack I threw together for testing purposes. I was going to go searching for a better way to actually remove the extension in a bit but I guess I don't have to do that now.

Thank you for saving me some time,
Matthew Margolis

Hi,

"Mehr, Assaph (Assaph)" <assaph@avaya.com> writes:

You're probably trying to remove the extension. Take a look at File
class methods: basename, extname, dirname etc. You can strip extension
by:
  base_name = textfilename.delete File.extname(textfilename)

% irb

textfilename = "foo.obj"

=> "foo.obj"

textfilename.delete File.extname(textfilename)

=> "f"

File.basename(textfilename, ".*")

=> "foo"

···

--
eban

WATANABE Hirofumi wrote:

Hi,

"Mehr, Assaph (Assaph)" <assaph@avaya.com> writes:

You're probably trying to remove the extension. Take a look at File
class methods: basename, extname, dirname etc. You can strip extension
by:
base_name = textfilename.delete File.extname(textfilename)
   
% irb

textfilename = "foo.obj"
     

=> "foo.obj"

textfilename.delete File.extname(textfilename)
     

=> "f"

File.basename(textfilename, ".*")
     

=> "foo"

I ended up going with
File.basename(textfilename, ".txt") That left me with just the pre-extension part of the file name.

-Matthew Margolis