Well starting a new process to read a directory and write it to a file, then to read that file, is definitely not the most efficient approach. If you're prepared to put up with that overhead then it really doesn't matter which variant on system you use.

Anyway if you're on Windows you can use the WinAPI functions for parsing a directory, but they're tricky to figure out and even I just copy stuff from MSDN. Here's a function from one of my projects:
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);
}
This won't compile as is - you don't have the recurseFuncData structure or the skipDir() and recurseFunc() functions. I've left them in so you can see how it works and you'll need to at least comment them out to make it work. If you don't want to recurse over a whole directory tree then just remove the if (strcmp...) block, leaving the FILE_ATTRIBUTE_DIRECTORY block empty (or negate the test and move the else block into the if block).