[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Getting number of files in a folder
From: |
Dmitri A. Sergatskov |
Subject: |
Re: Getting number of files in a folder |
Date: |
Wed, 17 Mar 2010 16:27:27 -0500 |
On Wed, Mar 17, 2010 at 4:19 PM, David Bateman <address@hidden> wrote:
> Journeaux, Ian wrote:
>> I would like to get the number of files in a folder (The files are of the
>> form file0001.txt) so I can loop through each one of the files.
>>
>> Is there a way to do this within Octave?
>> This electronic message contains information from NewPage Corporation or
>> subsidiary companies,
>> which may be confidential, privileged or otherwise protected from
>> disclosure. The information is
>> intended to be used solely by the recipient(s) named. If you are not an
>> intended recipient, be
>> aware that any review, disclosure, copying, distribution or use of this
>> transmission or its
>> contents is prohibited. If you have received this transmission in error,
>> please notify NewPage
>> immediately at address@hidden
>>
> There are probably lots of ways of doing it but
>
> length (dir()) - 2
>
> should be a good means. The minus 2 is needed to exclude the pseudo
> directories "." and "..", though I can't remember if these appear under
> a version of Octave on windows, so perhaps you need to drop the "-2" in
> that case or do something like
>
> len = length(dir())
> if (!ispc())
> len -= 2;
> endif
>
> D.
>
> len = length
What David wrote is, of course, correct. But the whole approach to
cycle through all
the files in the current directory is better implemented as:
fn = glob("*"); # this could be modified if you need some subset,
e.g. glob("test_2010*.dat")
for ii = 1:rows(fn)
disp(fn{ii})
# do whatever you want to do with fn{ii} file
endfor
Sincerely,
Dmitri.
--