Getting number of files in a folder

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting number of files in a folder

ijourneaux
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 [hidden email].


_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Getting number of files in a folder

David Bateman
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 [hidden email].
>  
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
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Getting number of files in a folder

Dmitri A. Sergatskov
On Wed, Mar 17, 2010 at 4:19 PM, David Bateman <[hidden email]> 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 [hidden email].
>>
> 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.
--

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Getting number of files in a folder

Sergei Steshenko
In reply to this post by ijourneaux


--- On Wed, 3/17/10, Journeaux, Ian <[hidden email]> wrote:

> From: Journeaux, Ian <[hidden email]>
> Subject: Getting number of files in a folder
> To: "[hidden email]" <[hidden email]>
> Date: Wednesday, March 17, 2010, 1:31 PM
> 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 [hidden email].
>
>

Probably

[files, err, msg] = readdir (dir)

can help.

Regards,
  Sergei.


     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Getting number of files in a folder

Jaroslav Hajek-2
In reply to this post by ijourneaux
On Wed, Mar 17, 2010 at 9:31 PM, Journeaux, Ian
<[hidden email]> 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?

help glob

--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave