Forum: Ruby Re: 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.
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Berger, Daniel (Guest)
on 2006-04-12 21:30
(Received via mailing list)
> a different extension for a separate write file. I've tried this:
>
> txtfiles = Dir.glob("*.txt")
> txtfiles.each { |txtfile| File.basename("txtfile", "*.txt") }

Remove the quotes around txtfile.
Change "*.txt" to just ".txt".

Regards,

Dan
B58c6eef325656d513d26e2c3ae6bfd9?d=identicon&s=25 Peter Bailey (peterbailey)
on 2006-04-12 21:52
Berger, Daniel wrote:
>> a different extension for a separate write file. I've tried this:
>>
>> txtfiles = Dir.glob("*.txt")
>> txtfiles.each { |txtfile| File.basename("txtfile", "*.txt") }
>
> Remove the quotes around txtfile.
> Change "*.txt" to just ".txt".
>
> Regards,
>
> Dan

Thanks, Dan. I still get the same thing, though:
irb(main):008:0> txtfiles.each { |txtfile| File.basename(txtfile,
".txt") }

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

This gets the same result, too:

irb(main):012:0> txtfiles.each { |txtfile| File.basename(txtfile, ".*")
}

=> ["eula.txt", "libcurl.COPYING.txt", "openssl.LICENSE.txt",
"psout2.txt", "run
dll32.exe.Z-missing.txt"]
This topic is locked and can not be replied to.