필터 지우기
필터 지우기

Find a file in a large directory quickly

조회 수: 5 (최근 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
Naum Derzhi
Naum Derzhi 2016년 9월 8일
Thank you for your answer.
Yes, this is correct. I timed dir with and without pattern, and there is no discernible difference. I was hoping to find some flags/parameters which would force it to stop once one match is found. Like the 'once' argument in some find... functions. Or find some other function which would do the same. So far, no luck.
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by