Change working directory on a Linux based server
6 views (last 30 days)
Show older comments
Nicola Dall'Osto
on 22 Apr 2024
Edited: Nicola Dall'Osto
on 23 Apr 2024
I wrote a script that opens Medical Image Labeler and loads some images in it to be annotated by the user. When the command medicalImageLabeler(gTruth) is executed, the app opens and a popup window (see figure) asks the user to select the path of the new session folder and to enter the name of the session folder. I want the predefined path of the session folder to be the same of the current working directory.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1676186/image.png)
For example: if the current working directory is C:\Users\Myname\Documents, the predefined folder for the new Medical Image Labeler's session has to be C:\Users\Myname\Documents.
On my Windows PC I was able to obtain this behavior by setting the working directory with cd, pointing to the desired path (e.g. cd(userFolder) where userFolder = "C:\Users\Myname\Documents").
The solution above doesn't seem to work in the PCs connected to my department server, which run Linux. In this case the predefined folder for savings in the Medical Image Labeler app is always the MATLAB folder (e.g. C:\Users\Myname\Documents\MATLAB or similar in the linux environment, I don't rememeber exactly the folder path) even if run the code in a different folder and even if I change the working directory with cd before opening Medical Image Labeler.
Could it be a problem due to the different operating system? Is there a way to fix it?
5 Comments
Mario Malic
on 23 Apr 2024
Alright, took me a while to figure out what are you trying to do.
1. Check write permissions
So, first thing you should check is the write permissions on the Linux server. If app fails to create a folder because it is not permitted to do, it might offer a folder that you have permission to write to (I am not well-versed with Linux, so not sure if this is what is happening)
2. Why would you change the cd, I don't think this is recommended practice (unless you use private functions). What about adding that folder and subfolders to the path? It will add tiny bit of complexity when you open/save files, but it's worth it.
3. Can you add some code to notify you about the r/w permissions to the folder? Such as, when you call mkdir, check if the folder path isfolder, etc.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!