isdir does not work

조회 수: 13 (최근 30일)
saxocat
saxocat 2017년 2월 28일
댓글: dpb 2017년 3월 1일
Hello yesterday i made a scipt that could search for specific filetypes in sub dictories and it was working fine.
fileList= dir('C:\Users\xxx\xxx')
fileList= fileList(~[fileList.isdir]);
txtFiles = dir(fullfile(fileList, '*.txt'));
But when i restarted i my computer the script didn't work. I have tried debug it and the problem seems to be that
fileList= fileList(~[fileList.isdir]);
wont list any files in the subfolders (it returns nothing). And it's like it just stopped working when on turned on my computer this morning.
  댓글 수: 1
dpb
dpb 2017년 2월 28일
Since we can't see the content of the subject directory we can't tell much...the first (via crystal ball) guess is that you're not looking in the same subdirectory you were in yesterday. The script above looks ok on first blush; what is result for fileList?

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

채택된 답변

Jan
Jan 2017년 2월 28일
편집: Jan 2017년 2월 28일
Don't panik. Matlab does not magically stop to work.
Use the debugger to examine, what's going on:
fileList = dir('C:\Users\xxx\xxx')
What is the contents of fileList? Is it empty? If so, this must be empty also:
fileList = fileList(~[fileList.isdir])
This "wont list any files in the subfolders"? Of course, because filList does not contain files in subfolders also. Or does "\xxx\" contain a "\**\"?
After this command fileList is still a struct array. Then:
dir(fullfile(fileList, '*.txt'))
fails with an error message: fullfile needs a string or cell string as input, not a struct array.
I guess, that you run another function then you assume. Please set a breakpoint in the code and check, if it is reached at all.
  댓글 수: 6
Jan
Jan 2017년 3월 1일
@Image Analyst: I'm not sure if I like the new recursive dir(). For many years I thought about adding my own implementation to the FEX, preferrably as C-Mex. The world was waiting for this. But now... At least I have the chance to publish another progressbar. ;-)
dpb
dpb 2017년 3월 1일
I can't run the release here (no 32-bit version) so can't really try it out to see how it actually works in practice. I'd've thunk mimicking the OS command with a switch to request instead of mucking around with the file search string would've been the way to implement it, though.
I read the doc and didn't see another complaint I've lodged and requested as enhancement that can't see why wasn't implemented from the git-go is the ? wildcard character besides the *.
One can regexp after the fact, but often it's doable for a desired match straight from the search if had the ability to write the equivalent of the OS command. I never could understand why that wasn't just done to begin with.

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

추가 답변 (0개)

카테고리

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