Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

reading contents of a folder

Hi all,

I would appreciate if anyone could help me write a C program that can search for a file in a given folder.

Cheers
Rj

Comments

  • ndixonndixon Member Posts: 5
    : Hi all,
    :
    : I would appreciate if anyone could help me write a C program that
    : can search for a file in a given folder.
    :
    : Cheers
    : Rj
    :

    Not tested, but...

    [code]
    #include
    #include

    main()
    {
    struct dirent *entry;

    DIR *dh = opendir("/path/to/some/dir");

    while ((entry = readdir(dh)) != NULL) {
    printf("filename: %s
    ", entry->d_name);
    }

    closedir(dh);
    }
    [/code]
  • sreerajsreeraj Member Posts: 2
    Thx a lot...it works

    : : Hi all,
    : :
    : : I would appreciate if anyone could help me write a C program that
    : : can search for a file in a given folder.
    : :
    : : Cheers
    : : Rj
    : :
    :
    : Not tested, but...
    :
    : [code]:
    : #include
    : #include
    :
    : main()
    : {
    : struct dirent *entry;
    :
    : DIR *dh = opendir("/path/to/some/dir");
    :
    : while ((entry = readdir(dh)) != NULL) {
    : printf("filename: %s
    ", entry->d_name);
    : }
    :
    : closedir(dh);
    : }
    : [/code]:
    :

Sign In or Register to comment.