フィルターのクリア

Is there a command to add a path to ALL folders and subfolders?

217 ビュー (過去 30 日間)
Andy
Andy 2016 年 10 月 11 日
コメント済み: kamal aghazade 2021 年 7 月 11 日
Hi guys
-apologies if this has been asked before - I cannot find a solution anywhere!
I have a script which accepts functions and data from 5 different folders (which I need to keep separate).
Therefore I need to add paths to each folder every time I boot up matlab. Its a pain!
I run this script on different computers all the time - (using different OS's) - therefore cannot use ...
addpath('specific location') ... in my script, and therefore do it manually by right-clicking > addpaths .. :(
Is there a generic way to add a link to everything within a directory?.
ie - a line of code which could give me something like ...
addpath('every folder and subfolder in this directory')
My directory looks like ...
{MainFolder % [Master Directory with everything in it]
>- MasterScript.m % [ which calls stuff from folder 1-5 ]
>- Folder1
>- Folder2
>- Folder3
>- Folder 4
>-Folder 5}
I hope that makes sense. Its a pretty simple problem. Let me know if you have a solution (which doesnt involve moving files or making more folders!)
Thanks!

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 10 月 11 日

krishna chaitanya kalipatnapu
krishna chaitanya kalipatnapu 2020 年 9 月 27 日
% Determine where your m-file's folder is.
folder = fileparts(which(mfilename));
% Add that folder plus all subfolders to the path.
addpath(genpath(folder));
  1 件のコメント
Jan
Jan 2020 年 9 月 28 日
編集済み: Jan 2020 年 9 月 28 日
Of faster and saver:
folder = fileparts(mfilename('fullpath'));

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by