MATLAB: Folder in a directory

dir

How do you use dir to obtain the names of folders in a directory. I can use
files = dir('*.xls');
to obtain information on the excel files within a specified directory but I have a directory which has 4 folders by using dir I obtain the names of each of the files, how is it possible to save the name of each file so that I can refer to each older within a loop.
cheers

Best Answer

A = dir % you get everything in current directly of matlab. or if you want to explicitly mention any directory path then you can do it like this.
A = dir('/yourpath');
now A has all files and directories. So you can access by loop
A(1).name
to get only Directory indexes you can do following code.
myDir = find(vertcat(A.isdir));
now myDir has indexes of directory(folders only).
to print the name of directory to confirm, you can do it like this.
A(myDir).name
where first two are only the pointers. you can always start your loop from 3. Ignore first two indexes.