Selecting files from a directory

3 views (last 30 days)
Cheggers on 11 Oct 2021
Commented: Cheggers on 11 Oct 2021
Probably a simple question but i currently use
sims = uigetdir ('C:\Matlab')
info = dir(fullfile(sims,'*.in'))
list = {}
Which brings up the popup window where i selected my folder, in this case 'RRfiles' which then gives me the list of the files in there and away we go. I am trying to do this without having to select the folder manually.
I have tried sims = dir ('C:\Matlab\RRfiles') which does tell me how many files are in there but the answer should be 26 and it is actually 28 because of '.' and '..' so i need a way of filtering out these files just like before. but putting info = dir(fullfile(sims,'*.in')) afterwards doesnt work. Any advice would be appreicated.

Accepted Answer

Chunru on 11 Oct 2021
Edited: Chunru on 11 Oct 2021
sims = pwd; %uigetdir ('C:\Matlab')
save sims % create a file
info = dir(fullfile(sims,'*.in'))
info = struct with fields:
name: '' folder: '/users/mss.system.GGGSp8' date: '11-Oct-2021 11:53:45' bytes: 199 isdir: 0 datenum: 7.3844e+05
list = {info(~[info.isdir]).name} % this will separate folders from files
list = 1×1 cell array
Cheggers on 11 Oct 2021
Right that makes sense now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by