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 Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by