Skip to content
Advertisement

Getting the path to a users documents folder on Linux and MacOSX

I’m currently developing a GUI using Matlab and I need to get the directory of the standard document folder of the user. Under windows I use this:

command = 'echo %USERPROFILE%Documents';
[status,docpath] = system(command);

and it works perfectly. Now I planned on doing the same for Linux and Mac with the system(command), but I have no idea what the actual command must look like under these OS. Thanks for your help!

Advertisement

Answer

On Linux the tilde ~ folder is used instead of %USERPROFILE%.

~ is, usually the,equivalent /home/username in which you’ll find the ‘Documents’ folder as in your example. The folder pointed by ‘~’ will be adapted in function of the user.

Here is an example on what is on ‘~’

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement