On 8/4/2013 5:41 PM, Pete wrote:
> dpb <none@non.net> wrote in message <ktmf7b$1hh$1@speranza.aioe.org>...
>
>> You can't guarantee any order of files returned by dir...to ensure
>> processing in sequence you'll need to sort the directory by name. That
>> minor ( :) ) point aside, do a dir() on each subdirectory you need and
>> work on those in sequence -- sotoo of
>>
>> for i=1:numDirsToProcess
>> d{i}=dir(fullfile(dirname(i),'*.txt'));
>> end
>>
>> Above is cell array of directory structures, one for each subdir
>> Now go thru them...
>>
>> for i=1:length(d)
>> for j=i:length(d{i})
>> ...
>> end
>> end
>>
>> Arrange the logic within the loops to get the ones you want from which
>> directory; maybe it's better to loop over the files first; depends on
>> just what you want to do...
>>
>> --
>>
> Ok I think I understand what you are trying to explain, are you saying
> make a directory of each batch and then process each directory within
> one loop? I'm having trouble following your code though and can't make
> sense of the first bit.
The first loop does a dir() on each subdirectory you've got a group of
files in. Just as the one that you have in your original code, not
you've got a cell array of those directory structures each of which is
the list in the corresponding subdirectory.
It's not clear just how you want/need to process the files "together" --
the same file name from each of the directories or a group of files from
each or what? If it's getting the same file from each of the
subdirectories it may be simpler to do the outer loop on a given
directory and the process it and for each file you find go thru the
other loop of subdirectories to get that same file from it.
All depends on just what you're trying to do...
My first loop assumes you're in a higher-level directory and have the
various subdirectory names in a dirname() (cell) array so
fullfile(dirname(i),'*.txt'))
is just the string
'directoryname_i\*.txt'
for each directory. Try it at the command line and see what it
does...same way, do
d{1}=dir('*.txt');
d{2}=dir('*.txt');
d
and see what you get...
--
> dpb <none@non.net> wrote in message <ktmf7b$1hh$1@speranza.aioe.org>...
>
>> You can't guarantee any order of files returned by dir...to ensure
>> processing in sequence you'll need to sort the directory by name. That
>> minor ( :) ) point aside, do a dir() on each subdirectory you need and
>> work on those in sequence -- sotoo of
>>
>> for i=1:numDirsToProcess
>> d{i}=dir(fullfile(dirname(i),'*.txt'));
>> end
>>
>> Above is cell array of directory structures, one for each subdir
>> Now go thru them...
>>
>> for i=1:length(d)
>> for j=i:length(d{i})
>> ...
>> end
>> end
>>
>> Arrange the logic within the loops to get the ones you want from which
>> directory; maybe it's better to loop over the files first; depends on
>> just what you want to do...
>>
>> --
>>
> Ok I think I understand what you are trying to explain, are you saying
> make a directory of each batch and then process each directory within
> one loop? I'm having trouble following your code though and can't make
> sense of the first bit.
The first loop does a dir() on each subdirectory you've got a group of
files in. Just as the one that you have in your original code, not
you've got a cell array of those directory structures each of which is
the list in the corresponding subdirectory.
It's not clear just how you want/need to process the files "together" --
the same file name from each of the directories or a group of files from
each or what? If it's getting the same file from each of the
subdirectories it may be simpler to do the outer loop on a given
directory and the process it and for each file you find go thru the
other loop of subdirectories to get that same file from it.
All depends on just what you're trying to do...
My first loop assumes you're in a higher-level directory and have the
various subdirectory names in a dirname() (cell) array so
fullfile(dirname(i),'*.txt'))
is just the string
'directoryname_i\*.txt'
for each directory. Try it at the command line and see what it
does...same way, do
d{1}=dir('*.txt');
d{2}=dir('*.txt');
d
and see what you get...
--