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

44 次查看(过去 30 天)
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

回答(2 个)

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

请先登录,再进行评论。


Stephen23
Stephen23 2019-9-9
编辑:Stephen23 2019-9-9
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)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by