Get file name and extension in Ruby

前端 未结 1 1701
名媛妹妹
名媛妹妹 2021-01-30 02:33

I\'m working on a program to download a video from YouTube, convert it to MP3 and create a directory structure for the files.

My code is:

FileUtils.cd(\"         


        
1条回答
  •  孤街浪徒
    2021-01-30 03:29

    You can use the following functions for your purpose:

    path = "/path/to/xyz.mp4"
    
    File.basename(path)         # => "xyz.mp4"
    File.extname(path)          # => ".mp4"
    File.basename(path, ".mp4") # => "xyz"
    File.basename(path, ".*")   # => "xyz"
    File.dirname(path)          # => "/path/to"
    

    0 讨论(0)
提交回复
热议问题