Listing available files and directories in Matlab

主宰稳场 提交于 2020-01-05 13:00:08

问题


I would like to list available directories and text files in specific directories recursively in Matlab command window (and ultimately in an m-file). I know commands like ls are available, but I would like to know the text files available in a string or vector before I recursively read each text file in the following file system structure:

master (contains A and B, all directories)

A contains A1 and A2 (all directories)

A1 contains A11, A12, A13, A14 (all directories)

A11 contains 1.txt, 2.txt, ...

Would be great to hear some feedback! Thanks in advance!


回答1:


You can use DIR recursively.

The output of dir is a structure where the first and the second element are current and parent directory, respectively, and the rest are the contents of the folder listed. Step through those. If it's a directory (dirOutput.isdir == 1), call dir on it. If it's a file, add it to the list.

If you don't want to code this yourself, have a look around the Matlab File Exchange. Here's one of many solutions.



来源:https://stackoverflow.com/questions/3356624/listing-available-files-and-directories-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!