Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

folder search

Status
Not open for further replies.

jl3574

Programmer
Jun 5, 2003
76
CA
help!
i'm trying to put all the file names ( if any) from a given folder into an array of character...

can any one show me how i can do this? thx.
 
For which operating system and compiler?

Here's how to read a dir in linux
Code:
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

main()
{
    struct dirent *dr;
    DIR *dp = opendir(&quot;.&quot;);
    if ( dp != NULL ) {
        while ( (dr=readdir(dp)) != NULL ) {
            printf( &quot;%s\n&quot;, dr->d_name );
        }
        closedir( dp );
    }
    return 0;
}
 
You might try asking in a C++ group. However, directories aren't covered by either C or C++.
 
windoz

Code:
char filearray [5000] [513];

int ScanDir (char *dir)
{
    // This function scans a directory for all files.
    // Loads the filearray

    struct ffblk ffblk;
    int done;
    int x = 0;
    char *buff = new char [512];

    strcpy(buff, dir);
    strcat(buff, &quot;*.*&quot;);

    done = findfirst(buff, &ffblk, FA_DIREC + FA_SYSTEM + FA_HIDDEN + FA_RDONLY + FA_ARCH);

    while(!done)
    {
        if(strcmp(&quot;.&quot;, ffblk.ff_name) != 0 && strcmp(&quot;..&quot;, ffblk.ff_name) != 0)
        {
            if((ffblk.ff_attrib & FA_DIREC) == FA_DIREC);
            else
            {
                strcpy (filearray [x], ffblk.ff_name);

                x++;
            }
        }

        done = findnext(&ffblk);
    }

    delete buff;

    return x;
}

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top