MATLAB Answers

Find a file in a large directory quickly

10 ビュー (過去 30 日間)
Naum Derzhi
Naum Derzhi 2016 年 9 月 7 日
コメント済み: Walter Roberson 2016 年 9 月 8 日
I have a directory with thousands of files matching a pattern, and all I need is the name of any one of them. If I call dir(pattern), it takes a long time. I'd appreciate any ideas on speeding it up.
Thank you,
Naum

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 8 日
About the only possibility that might be faster would be to dir() the entire directory and do the pattern matching yourself. You would get all of the names together, of all of the files.
My expectation would be that doing that would be slower than what you already have, as the pattern matching that exists already is almost certainly more efficient than what you would implement in MATLAB.
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 8 日
You might be able to create some mex code for the task. See for example http://www.gnu.org/software/libc/manual/html_node/Accessing-Directories.html#Accessing-Directories

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

Community Treasure Hunt

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

Start Hunting!

Translated by