How to navigate between directories during program execution?

8 visualizaciones (últimos 30 días)
Yashar Mehmani
Yashar Mehmani el 7 de Jul. de 2011
Editada: Yashar Mehmani el 27 de Oct. de 2017
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 comentarios
Yashar Mehmani
Yashar Mehmani el 7 de Jul. de 2011
Yes that would help with reading the files, but how do I reach the function files?
per isakson
per isakson el 15 de Sept. de 2017
Editada: per isakson el 15 de Sept. de 2017
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.

Iniciar sesión para comentar.

Respuestas (1)

Honglei Chen
Honglei Chen el 7 de Jul. de 2011
Hi Yashar,
The following command may be of your interest
doc run
doc fullfile
HTH
  1 comentario
Yashar Mehmani
Yashar Mehmani el 7 de Jul. de 2011
Editada: Yashar Mehmani el 14 de Sept. de 2017
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by