Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove path and subpaths in matlab

I have been looking for a simple way to remove a bunch of paths from matlab. I am working with a fairly large program and it includes many paths in its directory. I also work with svn version handling and I use many branches, which in general contains some functions that are the same, some that are modified and some that only exists on one branch.

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

rmpath(path1,path2,...);

However, this requires typing each path by hand. Since all paths have a common base directory I wonder, are there anyway to use wild cards to remove the complete directory from the path? I use a windows machine.

like image 382
patrik Avatar asked Mar 27 '14 14:03

patrik


4 Answers

Try using genpath. Given the base directory as input, genpath returns that base directory plus all subdirectories, recursive.

rmpath(genpath(base_directory));
like image 118
Steve Osborne Avatar answered Nov 08 '22 03:11

Steve Osborne


There's no wildcard support. You can just write your own Matlab function to add and remove all the paths in your project, or to support regexp matching. It's convenient to make that part of the project itself, so it can be aware of all the dirs that need to be added or removed, and do other library initialization stuff if that ever becomes necessary.

like image 42
Andrew Janke Avatar answered Nov 08 '22 04:11

Andrew Janke


The genpath answer works for fragment* cases, but not a *fragment* case.

Clunky, but works:

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
like image 1
Denise Skidmore Avatar answered Nov 08 '22 04:11

Denise Skidmore


I have a shorter answer:

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
like image 1
Juan Sebastián Bahamonde Avatar answered Nov 08 '22 03:11

Juan Sebastián Bahamonde