Remove path from file name
31 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Douglas Anderson
le 11 Déc 2014
Commenté : Chad Greene
le 11 Déc 2014
Hello!
There's probably a simple tool for this, but I can't find it:
Have a string for a file name that includes the full path, like:
C:\Users\DougAnderson\Documents\MATLAB\SHtest\sig hole 1.xlsx
where the last part (the actual file name) may contain spaces. I would like to change this to, for example
sig hole 1
Thanks
Doug
0 commentaires
Réponse acceptée
Chad Greene
le 11 Déc 2014
Modifié(e) : Chad Greene
le 11 Déc 2014
You can use fileparts. I had to switch the direction of the slashes because I'm using a mac, but it should work on your machine keeping the slashes the way you wrote them:
[~,name,~] = fileparts('C:/Users/DougAnderson/Documents/MATLAB/SHtest/sig hole 1.xlsx')
name =
sig hole 1
2 commentaires
Sean de Wolski
le 11 Déc 2014
Chad, fullfile will handle filesep for you.
fullfile('C:\Documents/MATLAB')
Plus de réponses (2)
Azzi Abdelmalek
le 11 Déc 2014
s='C:\Users\DougAnderson\Documents\MATLAB\SHtest\sig\hole 1.xlsx'
out=regexp(s,'(?<=\\)[^\\]+$','match')
Voir également
Catégories
En savoir plus sur String Parsing dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!