A list file paths of the files in the folder

I want to create a list of all the files in a folder with relative paths to 2 steps upward parent folder. I have used this code so far:
o_file_list = dir(Dir_name);
for ii = 1:length(o_file_list);
[pathstr,name,extension] = fileparts(o_file_list(ii).name);
end
output = o_file_list;
But the thing is I know how to create a list of files in the folder, but I can't find any info how to construct relative paths to a folder of my choice. Any help would be appreciated.
Best, Gert

 Accepted Answer

Suppose you can address 'yourfile.m' in Dir_name from the 2 step upward folder using 'foo/bar/yourfile.m'. Then you can create these filenames by
d = dir(Dir_name);
filenames = cellfun(@(x) fullfile('foo/bar/', x), {d.name}, 'UniformOutput', false);

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

N/A
on 10 Nov 2015

Commented:

N/A
on 10 Nov 2015

Community Treasure Hunt

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

Start Hunting!