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.
Berger, Daniel (Guest)
on 2006-04-13 00:04
(Received via mailing list)
> >>
> 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
Peter B. (Guest)
on 2006-04-13 15:56
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?
This topic is locked and can not be replied to.