# Re: File basenames using File.basename . .

**URL:** <https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93875>\
**Category:** Ruby\
**Created:** [April 12, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93875 "2006-04-12T21:30:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [April 12, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93875/1 "2006-04-12T21:30:47Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [April 12, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93875/2 "2006-04-12T21:52:30Z")

</div>

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”]
