Setting working directory to Documents folder in user profile on Windows 7

6 views (last 30 days)
I would like to set the working directory to the Documents folder of the currently logged-on user on Windows 7 machines. I would like to do this in startup.m
I imagine something like:
username = getusername;
cd C:\Users\username\Documents
What would be the correct syntax or code in startup.m for this?
Thanks.

Answers (1)

Geoff Hayes
Geoff Hayes on 20 Jun 2014
I saw this function on the File Exchange, http://www.mathworks.com/matlabcentral/fileexchange/32523-getusername/content/getUserName.m, which pretty much does what you want in terms of getting the user name. With that, you can build a command string to change directories, and then evaluate that command
% get the user name
userName = getUserName();
% build the command string
command = ['cd C:\Users\' userName '\Documents'];
% evaluate the command
eval(command);
Try the above and see what happens!
  4 Comments

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!