simplify weird path name

8 次查看(过去 30 天)
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'

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by