Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Reading multiple txt files (http://www.go4expert.com/forums/reading-multiple-txt-files-t24056/)

Programming_Kills 2Dec2010 13:18

Reading multiple txt files
 
Hi All Good Morning.
Can any one please tell me how to read multiple text files inside a folder at a time.
thanks in Advance.
Have a Nice Day.

shabbir 2Dec2010 14:58

Re: Reading multiple txt files
 
Just like you would do one file you can read more than one file as well. I am not able to understand what you are trying.

Programming_Kills 2Dec2010 15:10

Re: Reading multiple txt files
 
Thanks Admin
i am reading a directory and trying to store the file names in a hash table..
but i just want to now how to read a directory of files.
i hope u will be clear now.
Regards

xpi0t0s 3Dec2010 14:54

Re: Reading multiple txt files
 
Which OS are you using? Which API or object model?
The answer is dependent on both.

xpi0t0s 3Dec2010 14:57

Re: Reading multiple txt files
 
For example here's some code from a project of mine, but this isn't going to be a lot of use to you if you're not using the Windows API:
Code:

void recurseDir(const char *dir,int recfunc)
{
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind;
        int bFin=0;
        char startDir[1024];
        strcpy_s(startDir,1024,dir);
        strcat_s(startDir,1024,"\\*.*");
        hFind=FindFirstFile(startDir,&FindFileData);
        while (!bFin)
        {
                if (hFind==INVALID_HANDLE_VALUE)
                        bFin=1;
                else
                {
                        if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                        {
                                // skip . and ..
                                if (strcmp(FindFileData.cFileName,".") && strcmp(FindFileData.cFileName,".."))
                                {
                                        char loc[1024];
                                        strcpy_s(loc,1024,dir);
                                        strcat_s(loc,1024,"\\");
                                        strcat_s(loc,1024,FindFileData.cFileName);
                                        if (recurseFuncData.skipSkipDirs && skipDir(FindFileData.cFileName,loc))
                                        {
                                                //printf("Skip dir '%s'\n",loc);
                                        }
                                        else
                                        {
                                                //printf("Recurse into directory '%s'\n",loc);
                                                recurseFuncData.dirCount++;
                                                recurseDir(loc,recfunc);
                                        }
                                }
                        }
                        else
                        {
                                //printf("Found file '%s'\n",FindFileData.cFileName);
                                //recurseFuncData.fileCount++;
                                strcpy_s(recurseFuncData.fromDir,1024,dir);
                                if (!recurseFunc(recfunc,&FindFileData))
                                        bFin=1;
                        }
                }
                if (!FindNextFile(hFind,&FindFileData))
                        bFin=1;
        }
        FindClose(hFind);
}



All times are GMT +5.5. The time now is 12:54.