#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0

    Number of images in directory


    I'm looking for a function that allow to count number of images under a directiry.

    i'm using linux and opencv based in C++
    there is any function that allow that ?

    thanks and regards
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    opendir()
    readdir()
    closedir()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,896
    Rep Power
    481
    This is a job for the shell. I'd count the images in my ${HOME}/tmp directory using
    Code:
    file ~/tmp/* | gawk '{$1="";i += ($0~/image/)}END{print i}'
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0
    Originally Posted by b49P23TIvg
    This is a job for the shell. I'd count the images in my ${HOME}/tmp directory using
    Code:
    file ~/tmp/* | gawk '{$1="";i += ($0~/image/)}END{print i}'
    how to use this shell code in c++ ?
    thanks
  8. #5
  9. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,896
    Rep Power
    481
    You could go with
    system("command > some_file");
    and then read some_file
    but then again, you could also use---and this is how I'd solve the problem---

    inf = popen("command","r");
    if (NULL == inf) failure();
    if (expectation != fscanf(inf,"format",addresses)) another_failure();
    fclose(inf);

    /* warning---untested code without reading manuals. Anticipate errors */
    [code]Code tags[/code] are essential for python code and Makefiles!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0

    image's name in directory c++


    I would like to get the name of all the pictures in one direcory in c++.
    thanks

IMN logo majestic logo threadwatch logo seochat tools logo