How to navigate between directories during program execution?

9 次查看(过去 30 天)
I have a program in which I need to navigate from directory to directory (with the number of such directories being a variable), and read a bunch of files and execute a bunch of function files in them. Part of the reason they are put in different directories is that the M-files in these directories have the same names. My question is how:
  1. without changing the current directory (using the cd command)and
  2. without adding and removing paths with addpath and rmpath
Can I access these files selectively without creating conflict. Meaning every single time inside the program when I want to execute a function or read a file I could just do it knowing the full path of that folder. So all there would be known to you at each time is the full directories of the folders where these files are located.
One last note: Although I said the number of such directories is a variable, I know exactly which level they are located at, equivalently I know their full path every time at that juncture in my program (If this helps further ==> great, otherwise ==> ignore this last comment).
Thank you
  3 个评论
Yashar Mehmani
Yashar Mehmani 2011-7-7
Yes that would help with reading the files, but how do I reach the function files?
per isakson
per isakson 2017-9-15
编辑:per isakson 2017-9-15
For some reason this question appeared as Most Recent.
AFAIK: "[...] I want to execute a function [...] I could just do it knowing the full path of that folder" That is not possible, not without manipulating the search path or the current directory.
Had it been package folders it might be possible. Given
...\folder_in_the_search_path\+mypack\+mysubpack\myFcn.m
this call is possible
out = mypack.('mysubpack').myFcn( inarg )
However, I fail to find support in the documentation.

请先登录,再进行评论。

回答(1 个)

Honglei Chen
Honglei Chen 2011-7-7
Hi Yashar,
The following command may be of your interest
doc run
doc fullfile
HTH
  1 个评论
Yashar Mehmani
Yashar Mehmani 2011-7-7
编辑:Yashar Mehmani 2017-9-14
Thank you, but "run" cds to the folder and back. So unfortunately it wouldn't help. And "fullfile" is just a way of concatenating strings to make dirs.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Search Path 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by