Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
read *.mat from all the folders and subfolders

Subject: read *.mat from all the folders and subfolders

From: Vihang Patil

Date: 17 Apr, 2008 15:12:02

Message: 1 of 5

Hello All
I need to list all the *.mat files from the parent folder
and also its sub folders.
I am trying to use dir(). But it does not show any
relavant information about subfolders
for ex: I have a parent folder called "Solutions" and in
that I have around 6 sub folders
like "A", "B", "C", "D" ,"E" ,"F".
There are mat files in all the subfolders which I need to
list in the listbox. How can that be achieved?
Regards
Vihang

Subject: read *.mat from all the folders and subfolders

From: French Caro

Date: 17 Apr, 2008 15:33:01

Message: 2 of 5

"Vihang Patil" <vihang_patil@yahoo.com> wrote in message
<fu7pc2$7lq$1@fred.mathworks.com>...
> Hello All
> I need to list all the *.mat files from the parent folder
> and also its sub folders.
> I am trying to use dir(). But it does not show any
> relavant information about subfolders
> for ex: I have a parent folder called "Solutions" and in
> that I have around 6 sub folders
> like "A", "B", "C", "D" ,"E" ,"F".
> There are mat files in all the subfolders which I need to
> list in the listbox. How can that be achieved?
> Regards
> Vihang
Hi
With dir you also an have the subdirectories :
d=dir(yourDir)
for i=1:length(d)
   if d(i).isdir == 1 %directory
     %do whatever or recurse if you have created a function
   else
     %test if it is a MAT-file and store it
   end
end

Subject: read *.mat from all the folders and subfolders

From: Vihang Patil

Date: 17 Apr, 2008 15:42:01

Message: 3 of 5

"French Caro " <caro95470@nospam.free.fr> wrote in message
<fu7qjd$nvm$1@fred.mathworks.com>...
> "Vihang Patil" <vihang_patil@yahoo.com> wrote in message
> <fu7pc2$7lq$1@fred.mathworks.com>...
> > Hello All
> > I need to list all the *.mat files from the parent
folder
> > and also its sub folders.
> > I am trying to use dir(). But it does not show any
> > relavant information about subfolders
> > for ex: I have a parent folder called "Solutions" and
in
> > that I have around 6 sub folders
> > like "A", "B", "C", "D" ,"E" ,"F".
> > There are mat files in all the subfolders which I need
to
> > list in the listbox. How can that be achieved?
> > Regards
> > Vihang
> Hi
> With dir you also an have the subdirectories :
> d=dir(yourDir)
> for i=1:length(d)
> if d(i).isdir == 1 %directory
> %do whatever or recurse if you have created a
function
> else
> %test if it is a MAT-file and store it
> end
> end
>
I also tried this function
[a c] = dos(['dir /s /b *.mat']);
which, gives me the path's of all mat files in all the
subdirectories, but the <c> variable I get is of type
char. How do I convert this into a cell format so that I
can indivisually read the mat files.

Regards
Vihang

Subject: read *.mat from all the folders and subfolders

From: Dan Haeg

Date: 17 Apr, 2008 16:12:02

Message: 4 of 5

"Vihang Patil" <vihang_patil@yahoo.com> wrote in message
<fu7pc2$7lq$1@fred.mathworks.com>...
> Hello All
> I need to list all the *.mat files from the parent folder
> and also its sub folders.
> I am trying to use dir(). But it does not show any
> relavant information about subfolders
> for ex: I have a parent folder called "Solutions" and in
> that I have around 6 sub folders
> like "A", "B", "C", "D" ,"E" ,"F".
> There are mat files in all the subfolders which I need to
> list in the listbox. How can that be achieved?
> Regards
> Vihang

The file called "fuf" on the file exchange does what you
want I think.

Dan

Subject: read *.mat from all the folders and subfolders

From: Vihang Patil

Date: 21 Apr, 2008 05:09:02

Message: 5 of 5

"Dan Haeg" <haegd@msoe.edu> wrote in message <fu7ssh$et0
$1@fred.mathworks.com>...
> "Vihang Patil" <vihang_patil@yahoo.com> wrote in message
> <fu7pc2$7lq$1@fred.mathworks.com>...
> > Hello All
> > I need to list all the *.mat files from the parent
folder
> > and also its sub folders.
> > I am trying to use dir(). But it does not show any
> > relavant information about subfolders
> > for ex: I have a parent folder called "Solutions" and
in
> > that I have around 6 sub folders
> > like "A", "B", "C", "D" ,"E" ,"F".
> > There are mat files in all the subfolders which I need
to
> > list in the listbox. How can that be achieved?
> > Regards
> > Vihang
>
> The file called "fuf" on the file exchange does what you
> want I think.
>
> Dan


Thanks Dan
That was exactly what I needed.
Regards
Vihang

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us