Separate path string into drive and folders

515 views (last 30 days)
Hi,
using fileparts brings the path, the name and the exentension of a fullfile (e.g., C:\user\files\myFile.txt). Is there a function that separates the path into drive and folders, so that drive = 'C:' folder1 = 'user' folder2 = 'files' ?
Thx, Philipp

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 24 Jul 2013
s='C:\user\files\myFile.txt'
out=regexp(s,'\','split')
  2 Comments

Sign in to comment.

More Answers (1)

Christian Schwermer
Christian Schwermer on 9 Sep 2018
The shortest solution is to split the string using filesep as delimeter. filesep returns the platform-specific file separator "\" or "/".
pathparts = strsplit(s,filesep);

Categories

Find more on File Name Construction in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!