# How I can get name of file?

**URL:** <https://www.ruby-forum.com/t/how-i-can-get-name-of-file/61640>\
**Category:** Ruby\
**Created:** [May 25, 2006, 8:07pm UTC](https://www.ruby-forum.com/t/how-i-can-get-name-of-file/61640 "2006-05-25T20:07:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f04885/32.png) [@ilyas](https://www.ruby-forum.com/u/ilyas)\
**Post date:** [May 25, 2006, 8:07pm UTC](https://www.ruby-forum.com/t/how-i-can-get-name-of-file/61640/1 "2006-05-25T20:07:20Z")

</div>

I have this is string:  
/adfsd/dfsdf/funny-videos—gay-fight.mpeg

and I have this code:  
@original\_file\_path = file\_path  
name = @original\_file\_path.match(//[a-zA-Z0-9\_-]+./)  
if name  
puts name.values\_at(0)  
end

Result of code is  
/funny-videos—gay-fight.

I want to get it: funny-videos—gay-fight  
how I can get name of file?

---

<div class="post-metadata">

**Author:** ![ilyas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f04885/32.png) [@ilyas](https://www.ruby-forum.com/u/ilyas)\
**Post date:** [May 25, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/how-i-can-get-name-of-file/61640/2 "2006-05-25T20:15:54Z")

</div>

On 5/25/06, Ilyas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have this is string:  
> /adfsd/dfsdf/funny-videos—gay-fight.mpeg  
> [snip]
> 
> I want to get it: funny-videos—gay-fight  
> how I can get name of file?

irb(main):001:0\>  
File.basename(‘/adfsd/dfsdf/funny-videos—gay-fight.mpeg’, ‘.mpeg’)  
=\> “funny-videos—gay-fight”

Ryan
