search specific file under current direction

1 回表示 (過去 30 日間)
wenchao zhang
wenchao zhang 2023 年 11 月 22 日
コメント済み: wenchao zhang 2023 年 11 月 22 日
hello, i want search all the file with a .m extension under one routine, cd to the serach top level, as following, folders contains subfolders, it shall search all the folders and the files within folder, and check if .m file exist, the .m file shall be collect in a txt file or excel file, any one can give some suggestion.

採用された回答

Pratyush
Pratyush 2023 年 11 月 22 日
Hi Wenchao,
I understand that you want to search all the file with a .m extension under one routine.
You could use "dir" function in MATLAB to search for files and directories. Navigate to the top level folder. Then run the following command:
var = dir("**/*.m");
fileID = fopen('element_names.txt','w');
for i = 1:length(var)
fprintf(fileID,'%s\n', var(i).name);
end
fclose(fileID);
"element_names.txt" would contatin the name of all the .m files in the current folder and within all of its subfolders.
Hope this helps.
  3 件のコメント
wenchao zhang
wenchao zhang 2023 年 11 月 22 日
i mean, some of my file is repeated, not caused by your script.
wenchao zhang
wenchao zhang 2023 年 11 月 22 日
i try used following command before, now it is obviously can not used like this.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by