Reading directories in matlab

I want to read files from a directory in matlab. Then I need to check if this is a file or directory, and then process it. Can someone provide me a code snippet for this? or suggest a link for this?

+4
source share
3 answers

Perhaps take a look at the MathWorks website, they always have interesting examples and useful notes. For instance:

FileOperations

+1
source

The DIR function returns an array of structures, one for each directory entry. One element of the structure is a flag named isdir .

 mydir = 'c:\test'; allentries = dir(mydir); % array of all files and dirs within target diridxs = [allentries.isdir]; alldirs = allentries(diridxs); % array of all the dirs allfiles = allentries(~diridxs); % array of all the files for ctr = 1:length(allfiles) disp(allfiles(i).name) 

Please note that catalog entries are included . and .. which can be confusing when you try to parse a directory tree recursively ...

+4
source

I wrote a blog that addresses at least part of your problem: http://blogs.mathworks.com/loren/2006/08/02/processing-a-set-of-files/

- Loren

+4
source

Source: https://habr.com/ru/post/1301536/


All Articles