matlab 获取当前文件所在路径的上一级路径

12203阅读 0评论2012-09-05 renxiaobin32132
分类:WINDOWS

used functions:

mfilename(): name of the current m-file
fileparts(): get the path string part
filesep: '/' or '\'
strfind(): find a substring from an objective string

code:

currentDepth = 1; % get the supper path of the current path
currPath = fileparts(mfilename('fullpath'));% get current path
fsep = filesep;
pos_v = strfind(currPath,fsep);
p = currPath(1:pos_v(length(pos_v)-currentDepth+1)-1); % -1: delete the last character '/' or '\' 
上一篇:VC递归获取指定目录下的所有文件名字及路径
下一篇:C++删除重复行