Selecting files from a directory
1 回表示 (過去 30 日間)
古いコメントを表示
Probably a simple question but i currently use
sims = uigetdir ('C:\Matlab')
info = dir(fullfile(sims,'*.in'))
list = {info.name}
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.
0 件のコメント
採用された回答
Chunru
2021 年 10 月 11 日
編集済み: Chunru
2021 年 10 月 11 日
sims = pwd; %uigetdir ('C:\Matlab')
save test.in sims % create a file
info = dir(fullfile(sims,'*.in'))
list = {info(~[info.isdir]).name} % this will separate folders from files
5 件のコメント
Chunru
2021 年 10 月 11 日
Rik is right. I am using pwd and a file to demonstrate the commands later. It is the line "list = {info(~[info.isdir]).name}" that remove the '.' and '..' folders.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Search Path についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!