From: Vy Lam on
Hi Everyone,

I am in need of a code that can best explore and store a
directory hierarchy for subsequent visiting/processing.
1. Given x subfolders in current folder
2. Given each x has y (variable) sub-subfolders
3. Each y sub-subfolders have z (variable) sub-sub-
subfolders
4. The number of subfolder levels is variable
5. There are a random number of data files in each
subfolder that needs processing.

Is there a better way than just simply iterating through
the directory structure using dir commands?

My other need is to generate and save plots without them
displayed on the monitor.
From: Walter Roberson on
In article <fvppti$qet$1(a)fred.mathworks.com>,
Vy Lam <vlam(a)removethis.mcw.edu> wrote:

>I am in need of a code that can best explore and store a
>directory hierarchy for subsequent visiting/processing.
>1. Given x subfolders in current folder
>2. Given each x has y (variable) sub-subfolders
>3. Each y sub-subfolders have z (variable) sub-sub-
>subfolders
>4. The number of subfolder levels is variable
>5. There are a random number of data files in each
>subfolder that needs processing.

>Is there a better way than just simply iterating through
>the directory structure using dir commands?

Not really, no. You could replace some of the work of dir()
by using a perl routine, but the perl routine is going to end up
doing the same work anyhow.

About the only real question in such situations is whether to
go "depth first" or "breadth first". When you encounter
subdirectory T in the middle of your current directory, do you
process the contents of T before you finish processing the
current directory ("depth first"), or do you keep track of the
subdirectories and process them after you have processed the
current directory ("breadth first"). The logic and storage requirements
are usually a little easier for "depth first" but both are completely
valid choices.
--
"They called it golf because all the other four letter words
were taken." -- Walter Hagen
From: Vy Lam on

> Not really, no. You could replace some of the work of dir
()
> by using a perl routine, but the perl routine is going to
end up
> doing the same work anyhow.
-----------------

Darn, I was afraid of that.

Thank you very much for your answer though. I also noticed
that I forgot to thank everyone for reading.

Best wishes!



From: carlos lopez on
"Vy Lam" <vlam(a)removethis.mcw.edu> wrote in message
<fvppti$qet$1(a)fred.mathworks.com>...
> My other need is to generate and save plots without them
> displayed on the monitor.
You can issue something like:
h=figure(gcf+1);set(h,'visible','off')
and then plot what you want. "gcf+1" attempts to create a
new figure; this will require some extra caution because you
(for example) are working within figure 3, but if figure 4
already exists then the plots will be superimposed and/or
affected by your further work.
If for some reason you cannot set visible as off, you can
open the figure outside the visible area, like
h=figure(gcf+1);set(h,'position',[1000 1000 560 420])
Hope this helps
Regards
Carlos

From: Peter Boettcher on

["Vy Lam" originally asked about recursive directory stuff]

"Vy Lam" <vlam(a)removethis.mcw.edu> writes:

[Walter Robinson said:]

>> Not really, no. You could replace some of the work of dir () by using
>> a perl routine, but the perl routine is going to end up doing the
>> same work anyhow.
> -----------------
>
> Darn, I was afraid of that.
>
> Thank you very much for your answer though. I also noticed
> that I forgot to thank everyone for reading.

It really isn't that bad... write one recursive directory listing
function that returns a list of all files underneath. Then when you
find another directory, call the function again.

function l = recursive_dir(fname)

l = cell(0);
d = dir(fname);
for i = 1:length(d)
if(strcmp(d(i).name, '.') || strcmp(d(i).name, '..'))
continue;
end

newname = fullfile(fname, d(i).name);
if(d(i).isdir)
l = [l; recursive_dir(newname)];
else
l = [l; newname];
end
end



-Peter