From: Ana-Maria Cuculescu on
Hello,

How can I count the image files in active directory ?

For instance, if I have 9 images in the active directory, I want to write a code that counts the number of images in my directory and returns this number: 9.

Thanks.
From: Sean on
"Ana-Maria Cuculescu" <amcuculescu(a)gmail.com> wrote in message <hpcsig$bkr$1(a)fred.mathworks.com>...
> Hello,
>
> How can I count the image files in active directory ?
>
> For instance, if I have 9 images in the active directory, I want to write a code that counts the number of images in my directory and returns this number: 9.

One way, though there are probably better:

my_dir = ls;
found = strfind(my_dir,'jpg');% use your image extension in place of jpg. e.g. 'tif' 'raw'
number_images = numel(found);
From: Ana-Maria Cuculescu on
Hi Sean,

It doesn't work:

my_dir = ls;
found = strfind(my_dir,'jpg');

??? Error using ==> strfind
Input strings must have one row.

although I have a file named jpg.jpg in the directory...

Thanks in advance.
From: Steven Lord on

"Ana-Maria Cuculescu" <amcuculescu(a)gmail.com> wrote in message
news:hpcvrg$6ms$1(a)fred.mathworks.com...
> Hi Sean,
>
> It doesn't work:
>
> my_dir = ls;
> found = strfind(my_dir,'jpg');
>
> ??? Error using ==> strfind
> Input strings must have one row.
>
> although I have a file named jpg.jpg in the directory...
>
> Thanks in advance.
>

For each of the image file extensions you want to count, use DIR.

D = dir('*.jpg');
numberOfJpg = numel(D);

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: us on
"Ana-Maria Cuculescu" <amcuculescu(a)gmail.com> wrote in message <hpcsig$bkr$1(a)fred.mathworks.com>...
> Hello,
>
> How can I count the image files in active directory ?
>
> For instance, if I have 9 images in the active directory, I want to write a code that counts the number of images in my directory and returns this number: 9.
>
> Thanks.

one of the many solutions

rpat='^.+((\.jpg)|(\.asv)|(\.txt))$'; % <- select your file extensions...
d=dir;
d={d.name}.';
f=regexp(d,rpat,'match');
f=[f{:}].';
disp(f);

us