Delete path and subfolders in matlab

I was looking for an easy way to remove a bunch of paths from Matlab. I work with a fairly large program and includes many paths in my directory. I also work with svn version processing, and I use many branches, which usually contain the same functions, some of which are modified and some of them exist in only one branch.

The problem is that when I set the path for one branch (using a custom function) and then I want to change the directory to another path, the first part is annoying to delete. I used

rmpath(path1,path2,...);

However, this requires entering each path manually. Since all the paths have a common base directory, I wonder if there are anyway use wild cards to remove the full directory from the path? I am using a windows machine.

+4
source share
4 answers

Try using genpath. Given the base directory as input, genpath returns this base directory and all subdirectories recursive.

rmpath(genpath(base_directory));
+10
source

No wildcard support. You can simply write your own Matlab function to add and remove all paths in your project or maintain regular expression matching. It is convenient to do this part of the project itself, so it can know about all the disks that need to be added or removed, and make other library initialization files if it ever becomes necessary.

+1
source

genpath fragment*, *fragment*.

Clunky, :

pathlist = path;
pathArray = strsplit(pathlist,';');
numPaths = numel(pathArray);
for n = 1:numPaths
    testPath = char(pathArray(n))
    isMatching = strfind(testPath,'pathFragment')
    if isMatching
        rmpath(testPath);
    end
end
+1

:

function rmpathseb(directory)

% Retrieve the subfolders
folders = dir(directory);

% Remove folders one by one
% The first two are '.' and '..'
for i = 3 : length(folders);

    rmpath([pwd , '\' , directory , '\' , folders(i).name]);

end

end
+1

Source: https://habr.com/ru/post/1533744/


All Articles