Project

General

Profile

Actions

Feature #6671

open

File.split_all and File.split_root

Added by trans (Thomas Sawyer) over 11 years ago. Updated about 6 years ago.

Status:
Assigned
Target version:
-
[ruby-core:45965]

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

Updated by trans (Thomas Sawyer) over 11 years ago

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

Updated by marcandre (Marc-Andre Lafortune) over 11 years ago

How about:

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

And

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

Updated by Eregon (Benoit Daloze) over 11 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#each_filename (for split_all) ?

Updated by trans (Thomas Sawyer) over 11 years ago

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

Updated by ko1 (Koichi Sasada) over 11 years ago

  • Assignee set to mame (Yusuke Endoh)

mame-san: Please judge this ticket.

Updated by mame (Yusuke Endoh) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee changed from mame (Yusuke Endoh) to matz (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

Updated by mame (Yusuke Endoh) over 11 years ago

  • Target version changed from 2.0.0 to 2.6
Actions #8

Updated by naruse (Yui NARUSE) about 6 years ago

  • Target version deleted (2.6)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0