simplify weird path name

조회 수: 7 (최근 30일)
Wesley Ooms
Wesley Ooms 2014년 5월 7일
편집: Stephen23 2015년 8월 31일
if i have a valid pathname like this:
C:\folder\\\\subfolder\.\.\..\..\documents\map\dir\\\..\location\
how can i change that to its simplest form in a simple way?
one way i came up with is
stupidpath='C:\folder\\\\subfolder\.\.\..\..\documents\map\dir\\\..\location\'
currentpath=cd
cd stupidpath
cleverpath = cd
cd currentpath
and another way would be with strrep, strfind, etc. but that is both quite cumbersome. is there another, easy way?

채택된 답변

Wesley Ooms
Wesley Ooms 2014년 5월 7일
ok, solved myself:
p='C:\folder\\\\subfolder\.\.\..\..\documents\map\dir\\\..\location\'
p=p(p~='.')
p=p(p~='\'|p([2:end end])~='\')
  댓글 수: 2
Slim
Slim 2015년 8월 31일
This solution yields 'C:\folder\subfolder\documents\map\dir\location', so it doesn't take into account the relative paths.
I would have expect a result more like 'C:\documents\map\location'
Stephen23
Stephen23 2015년 8월 31일
편집: Stephen23 2015년 8월 31일

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Filename Construction에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by