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

52 Ansichten (letzte 30 Tage)
MATLAB Noob
MATLAB Noob am 9 Sep. 2019
Bearbeitet: Stephen23 am 9 Sep. 2019
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

Antworten (2)

madhan ravi
madhan ravi am 9 Sep. 2019
s = what(Folder);
s.path
  7 Kommentare
MATLAB Noob
MATLAB Noob am 9 Sep. 2019
Bearbeitet: MATLAB Noob am 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 am 9 Sep. 2019
Is there a way to get the path file if there are no MATLAB files in the folder?

Melden Sie sich an, um zu kommentieren.


Stephen23
Stephen23 am 9 Sep. 2019
Bearbeitet: Stephen23 am 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)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by