码迷,mamicode.com
首页 > 其他好文 > 详细

basename/dirname 获取文件名/路径

时间:2014-08-28 17:58:25      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   for   文件   div   html   

http://ruby-doc.org/core-2.1.2/File.html#method-c-dirname

(1)basename(file_name [, suffix] ) → base_name 

Returns the last component of the filename given in file_name, which can be formed using bothFile::SEPARATOR and File::ALT_SEPARATOR as the separator when File::ALT_SEPARATOR is not nil. If suffix is given and present at the end of file_name, it is removed.

File.basename("/home/gumby/work/ruby.rb")          #=> "ruby.rb"
File.basename("/home/gumby/work/ruby.rb", ".rb")   #=> "ruby"


(2)dirname(file_name) → dir_name

Returns all components of the filename given in file_name except the last one. The filename can be formed using both File::SEPARATOR and File::ALT_SEPARATOR as the separator whenFile::ALT_SEPARATOR is not nil.

File.dirname("/home/gumby/work/ruby.rb")   #=> "/home/gumby/work"

 


basename/dirname 获取文件名/路径

标签:style   blog   http   color   ar   for   文件   div   html   

原文地址:http://www.cnblogs.com/iwangzheng/p/3942072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!