1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Reading multiple txt files

Discussion in 'C' started by Programming_Kills, Dec 2, 2010.

  1. Programming_Kills

    Programming_Kills New Member

    Joined:
    Jun 14, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    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.
     
  3. Programming_Kills

    Programming_Kills New Member

    Joined:
    Jun 14, 2010
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Which OS are you using? Which API or object model?
    The answer is dependent on both.
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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);
    }
    
     

Share This Page