# Re: File basenames using File.basename . .

**URL:** <https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93879>\
**Category:** Ruby\
**Created:** [April 12, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93879 "2006-04-12T22:04:29Z")\
**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, 10:04pm UTC](https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93879/1 "2006-04-12T22:04:29Z")

</div>

> > >
> 
> Thanks, Dan. I still get the same thing, though:  
> File.basename(txtfile, “.\*”)  
> }
> 
> =\> [“eula.txt”, “libcurl.COPYING.txt”, “openssl.LICENSE.txt”,  
> “psout2.txt”, “run  
> dll32.exe.Z-missing.txt”]

Oh, you’re just seeing what irb returns at the end of Array#each.

Try this:

txtfiles.each{ |txtfile|  
p File.basename(txtfile, ‘.txt’)  
}

If you want to change the results of the array inline, do this:

txtfiles.map!{ |txtfile| File.basename(txtfile ‘.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 13, 2006, 1:56pm UTC](https://www.ruby-forum.com/t/re-file-basenames-using-file-basename/93879/2 "2006-04-13T13:56:31Z")

</div>

Berger, Daniel wrote:

> > > >
> > 
> > Thanks, Dan. I still get the same thing, though:  
> > File.basename(txtfile, “.\*”)  
> > }
> > 
> > =\> [“eula.txt”, “libcurl.COPYING.txt”, “openssl.LICENSE.txt”,  
> > “psout2.txt”, “run  
> > dll32.exe.Z-missing.txt”]
> 
> Oh, you’re just seeing what irb returns at the end of Array#each.
> 
> Try this:
> 
> txtfiles.each{ |txtfile|  
> p File.basename(txtfile, ‘.txt’)  
> }
> 
> If you want to change the results of the array inline, do this:
> 
> txtfiles.map!{ |txtfile| File.basename(txtfile ‘.txt’) }
> 
> Regards,
> 
> Dan

Thanks, Dan. Both of your suggestions worked for me. Now, how could I  
fulfill my instructions in the filesystem itself, not just in the array?  
I know I can do it with a system(“ren \*.txt \*.”), but, how would I do it  
in RUBY?
