How to find the full file path with only a folder?

45 views (last 30 days)
I am given the string of a folder name
Folder = 'Wallpapers'
How would I get the full file path of the folder 'Wallpapers' so that it looks something like this:
C:\Users\Bob\Pictures\Wallpapers

Answers (2)

madhan ravi
madhan ravi on 9 Sep 2019
s = what(Folder);
s.path
  7 Comments
MATLAB Noob
MATLAB Noob on 9 Sep 2019
Edited: MATLAB Noob on 9 Sep 2019
My code is supposed to take the name of a folder and open a directory to it.
folder_name = 'Wallpapers';
s = what(folder_name);
path = s.path;
location = dir(path);
From what I've read, what() can only give the path of the folder if the folder contains MATLAB files.
MATLAB Noob
MATLAB Noob on 9 Sep 2019
Is there a way to get the path file if there are no MATLAB files in the folder?

Sign in to comment.


Stephen23
Stephen23 on 9 Sep 2019
Edited: Stephen23 on 9 Sep 2019
Until MATLAB has an inbuilt function for this, the general solution is to download one of these:
or use something like:
folder = '../Wallpapers';
prv = pwd();
cd(folder)
out = pwd()
cd(prv)

Categories

Find more on File Operations in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!