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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeFilename Construction についてさらに検索

製品

質問済み:

2014 年 5 月 7 日

編集済み:

2015 年 8 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by