e r l a n g : c o o k b o o k

Erlang.FileSplitPath
  Difference Topic FileSplitPath (r1.1 - 01 Sep 2004 - BrentAFulgham)
Added:
>
>

%META:TOPICINFO{author="BrentAFulgham" date="1093997854" format="1.0" version="1.1"}%

Splitting a Path into All of Its Parts

Problem

You want to split a path into all of its components.

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"]

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"]

Contributors

Based on work by GordonWeakliem.

-- BrentAFulgham - 01 Sep 2004 %META:FORM{name="CookbookForm"}% %META:FIELD{name="TopicType" title="TopicType" value="Recipe"}% %META:FIELD{name="ParentTopic" title="ParentTopic" value="FileRecipes"}% %META:FIELD{name="TopicOrder" title="TopicOrder" value="050"}%

 
 
Copyright © 2004 by the contributing authors. All material on the Erlang Cookbook web site is the property of the contributing authors.
This material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest