[ BoLa @ 12.01.2006. 16:31 ] @
Zanima me koja funkcija vrsi sljedece u C-u: vraca imena datoteka u zadanom direktoriju(kao dir u dosu)? Da li postoji takva funkcija? Koristim borland c++ 5.02.

Pregledao sam dosta zaglavlja ali nisam nasao odgovarajucu funkc.
[ X Files @ 12.01.2006. 18:18 ] @
Pogledaj u Help-u funkcije findfirst(), findnext(), ...

Ovo je copy/paste primer iz BCB Helpa (C Runtime Library Reference), i trebao
bi da se bez problema kompajlirta sa BC 5.02.

Pogledaj detaljnije (takodje u Help-u) 'ffblk' strukturu, koja ima i vise podataka
od samog imena, koje primer ispisuje...

Code:

/* findfirst and findnext example */

#include <stdio.h>
#include <dir.h>

int main(void)
{
   struct ffblk ffblk;
   int done;
   printf("Directory listing of *.*\n");
   done = findfirst("*.*",&ffblk,0);
   while (!done) 
   {
      printf("  %s\n", ffblk.ff_name);
      done = findnext(&ffblk);
   }

   return 0;
}
[ BoLa @ 12.01.2006. 18:26 ] @
Da, mislim da je to sto je trebalo. Ja sam takodjer nasao jos nesto na netu.

Code:

main()   { int count,i;
                struct direct **files;
                int file_select();
 
                if (getwd(pathname) == NULL )
                        { printf("Error getting path$\backslash$n");
                                exit(0);
                        }
                printf("Current Working Directory = %s$\backslash$n",pathname);
                count =
                  scandir(pathname, &files, file_select, alphasort);
 
                /* If no files found, make a non-selectable menu item */
                if         (count <= 0)
                        {         printf(``No files in this directory$\backslash$n'');
                                exit(0);
                        }
                printf(``Number of files = %d$\backslash$n'',count);
                for (i=1;i<count+1;++i)
                         printf(``%s  '',files[i-1]->d_name);
                printf(``$\backslash$n''); /* flush buffer */
        }


ova linija:

count = scandir(pathname, &files, file_select, alphasort);
Pa cu probati ...

Zaboravih include je ovo:
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/param.h>
#include <stdio.h>

[Ovu poruku je menjao BoLa dana 12.01.2006. u 19:27 GMT+1]