Separate path string into drive and folders
248 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Azzi Abdelmalek
2013-7-24
s='C:\user\files\myFile.txt'
out=regexp(s,'\','split')
2 个评论
Manuel Lera Ramirez
2018-6-5
编辑:Manuel Lera Ramirez
2018-6-5
For a general solution (would work on any OS) I would suggest
endout=regexp(s,filesep,'split')
Best
更多回答(2 个)
Christian Schwermer
2018-9-9
The shortest solution is to split the string using filesep as delimeter. filesep returns the platform-specific file separator "\" or "/".
pathparts = strsplit(s,filesep);
0 个评论
Dominique
2023-7-19
path = uigetdir()
foldername = strsplit(path,"\");
foldername = foldername(end);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Name Construction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!