Feature #6671

File.split_all and File.split_root

Added by Thomas Sawyer almost 2 years ago. Updated over 1 year ago.

[ruby-core:45965]
Status:Assigned
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:core
Target version:next minor

Description

=begin
Is there a method for this already?

File.split_all('a/b/c') #=> ['a','b','c']

If not I propose it be added. I've had need of such more than a few times.

It's too bad that File.split can't do this, as it would make more sense. And the current method be called split_base.

In addition split_root would be helpful.

root, path = File.split_all('a/b/c')
root #=> 'a'
path #=> 'b/c'
=end

History

#1 Updated by Thomas Sawyer almost 2 years ago

Typo in that last example, it should be split_root obviously.

#2 Updated by Marc-Andre Lafortune almost 2 years ago

How about:

'a/b/c'.split('/') # => ['a','b','c']

And

root, _, path = 'a/b/c'.partition('/')
root  #=> 'a'
path  #=> 'b/c'

#3 Updated by Benoit Daloze almost 2 years ago

marcandre (Marc-Andre Lafortune) wrote:

How about:

'a/b/c'.split('/') # => ['a','b','c']

And

root, _, path = 'a/b/c'.partition('/')
root  #=> 'a'
path  #=> 'b/c'

I guess that might be problematic for absolute paths:

> "/a/b/c".split '/'
=> ["", "a", "b", "c"]
> "/a/b/c".partition '/'
=> ["", "/", "a/b/c"]

Is the feature wanted Pathname#eachfilename (for splitall) ?

#4 Updated by Thomas Sawyer almost 2 years ago

Its also not so simple b/c of variation in file systems, e.g. a\b\c.

#5 Updated by Koichi Sasada over 1 year ago

  • Assignee set to Yusuke Endoh

mame-san: Please judge this ticket.

#6 Updated by Yusuke Endoh over 1 year ago

  • Status changed from Open to Assigned
  • Assignee changed from Yusuke Endoh to Yukihiro Matsumoto

I think I have no right to accept any feature.
Even if I have, I won't use the right without any particular reason.

Yusuke Endoh mame@tsg.ne.jp

#7 Updated by Yusuke Endoh over 1 year ago

  • Target version changed from 2.0.0 to next minor

Also available in: Atom PDF