how to open a file from the previous folder
Afficher commentaires plus anciens
Hello, I have a folder hierarchy like the one in the image, I'm running a script from folder B and what I want is to open an image that is in folder C, but the path to it can change, that is, I want the code to be the same regardless of whether the folder A is on the desktop or in my documents for example.

Does anyone know how to program that?
Réponse acceptée
Plus de réponses (2)
Amine BEROUAKEN
le 31 Jan 2024
Hello, you can use this code
imagePath = fileparts(pwd) + "\FloderCName\imageName.png";
Stephen23
le 31 Jan 2024
Note that there is absolutely no need to call PWD. Simply use '.' to refer to the current directory:
relativePathToC = './../C';
Catégories
En savoir plus sur Convert Image Type dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!