Split File Path
From Erlang Community
(Difference between revisions)
| Revision as of 02:39, 4 September 2006 (edit) Bfulgham (Talk | contribs) ← Previous diff |
Current revision (15:37, 14 June 2007) (edit) (undo) Defza (Talk | contribs) m (reverted spam... mmm...) |
||
| (3 intermediate revisions not shown.) | |||
Current revision
[edit] Problem
You want to split a path into all of its components.
[edit] Solution
The split function in the Erlang standard library module file will do this.
1> filename:split("C:\\winnt\\system32\\drivers\\etc").
["c:/","winnt","system32","drivers","etc"]
|
[edit] Discussion
You may want to find the path from the root directory to the item of interest. To do so, you will need to convert any relative pathnames to absolute path names, using the filename:absname function:
1> filename:split( filename:absname( "..\\..\\winnt\\system32\\drivers\\etc" )). ["c:/", "Program Files", "erl5.3.6.3", "..", "..", "winnt", "system32", "drivers", "etc"] |

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

