熊熊烈火雄壮 发表于 2012-9-6 15:20
谢谢。那请问下,如何去掉后缀和前面的父目录呢
e.g. others/fight1.data
取后:fight1 ...
File.basename(filename[, suffix])
Returns the final slash-delimited component of filename. If suffix is supplied and is identical to the end of filename, filename is returned without the suffix.
p File.basename("ruby/ruby.c") # => "ruby.c"
p File.basename("ruby/ruby.c", ".c") # => "ruby"
p File.basename("ruby/ruby.c", ".*") # => "ruby"
p File.basename("ruby/ruby.exe", ".*") # => "ruby"