Change working directory on a Linux based server

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.
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

I don't think the question is clear enough.
If I understand your question, the issue on Linux is that your app's cd is in ...Documents\MATLAB, whereas in Windows is in ...Documents\
Is it possible that you installed the app in different folder on Linux?
Maybe you can use environment variables to construct full directory to the folder depending if you are on Linux or Windows. Changing current directory may cause some issues (sometimes).
Maybe my question is not clear, I'm sorry. I'll try to clarify my issue.
I edited my script on Windows. By using cd to set the working directory before starting Medical Image Labeler, when this one ask me to select the folder path for the new MedicalLabelingSession, the predefined path shown in the cell next to the "Browse" button (see the screenshot in the question post) is exactly the working directory set by cd.
Let's say:
currentFolder = C:\Users\Myname\Documents\annotationSession
cd(currentFolder)
medicalImageLabeler(gTruth)
With this commands, the Medical Image Labeler app on startup creates the session folder (usually named as MedicalLabelingSession) in the annotationSession folder which has path C:\Users\Myname\Documents\annotationSession.
On Linux, but I am not sure if it a problem of Linux or if it is an issue due to the fact that I use a PC running on Linux server, the solution that works on Windows doesn't seem to work.
In fact, if I don't change the path of the MedicalLabelingSession folder that the app create on startup, it creates the folder in the predefined MATLAB folder, that is ususlly located at $home/Documents/MATLAB. For setting the correct folder I enter the correct path in the dialog box that appears when Medical Image Labeler starts.
I am searching for a solution that works also on Linux or on the Linux server to do the same thing I am able to do on Windows with the commands shown above.
I hope that this is clearer. Thank you.
@Mario Malic, what do you mean by "use environment variables to construct full directory to the folder"?
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.
In this step I'm not trying to create a folder. The folder needed for the MedicalLabelingSession already exists. I was only wandering why in Windows there is a certain behaviour and in Linux it is different. As I've explained before, in Windows, if I use cd to point to the folder where I want to store the MedicalLabelingSession, in this popup window, that opens when Medical Image Labeber starts, the folder is already the one that i've set with cd.
On the contrary, on linux, the folder that appears in the box in this popup window is not the folder set with cd, but it is the MATLAB installation folder. If I want to save the MedicalLabelingSession in the folder I want, I have to browse the folder and select it manually.

Sign in to comment.

 Accepted Answer

Nicola Dall'Osto
Nicola Dall'Osto on 23 Apr 2024
Edited: Nicola Dall'Osto on 23 Apr 2024
I resolved the issue by using userpath instead of cd.

More Answers (0)

Categories

Products

Release

R2024a

Community Treasure Hunt

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

Start Hunting!