I need to get all those files under D:\dic
and loop over them to further process individually.
Does MATLAB support this kind of operations?
It can be done in other scripts like PHP,Python...
I need to get all those files under D:\dic
and loop over them to further process individually.
Does MATLAB support this kind of operations?
It can be done in other scripts like PHP,Python...
I don't know a single-function method for this, but you can use
genpath
to recurse a list of subdirectories only. This list is returned as a semicolon-delimited string of directories, so you'll have to separate it using strread, i.e.dirlist = strread(genpath('/path/of/directory'),'%s','delimiter',';')
If you don't want to include the given directory, remove the first entry of
dirlist
, i.e.dirlist(1)=[];
since it is always the first entry.Then get the list of files in each directory with a looped
dir
.filesep
returns the directory separator for the platform on which MATLAB is running.This gives you a list of filenames with full paths in the cell array filenamelist. Not the neatest solution, I know.
You're looking for dir to return the directory contents.
To loop over the results, you can simply do the following:
This should give you output in the following format, e.g.: