Forum: Ruby File basenames using File.basename . . .

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-04-12 21:25
I need to truncate the extension of some of my files, so that I can add
a different extension for a separate write file. I've tried this:

txtfiles = Dir.glob("*.txt")
txtfiles.each { |txtfile| File.basename("txtfile", "*.txt") }

which yields this:

=> ["eula.txt", "libcurl.COPYING.txt", "openssl.LICENSE.txt",
"psout2.txt", "run
dll32.exe.Z-missing.txt"]

Obviously, it didn't strip the extensions. What am I doing wrong?

Thanks.
De60a566d8e2a8dec790d1f6741ad424?d=identicon&s=25 jay (Guest)
on 2006-04-12 22:59
don't think you need the wildcard:

> txtfiles.each { |txtfile| File.basename("txtfile", "*.txt") }
This topic is locked and can not be replied to.