All pastes #125151 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-08-10 13:12 UTC
rendered paste body
void LoopDirectories(char *pPath, void (*pFunc)(char*))
{
	char szCmd[256];
	char szBuffer[512];
	char *pTemp = NULL;
	FILE *pFile = NULL;

	memset(szCmd, 0, sizeof(szCmd));
	snprintf(szCmd, sizeof(szCmd) - 1, "ls %s > temp", pPath);
	system(szCmd);

	pFile = fopen("temp", "r");
	if(pFile == NULL)
	{
		return;
	}

	memset(szBuffer, 0, sizeof(szBuffer));
	while(fgets(szBuffer, sizeof(szBuffer) - 1, pFile))
	{
		pTemp = strstr(szBuffer, "\n");
		if(pTemp)
		{
			*pTemp = '\0';
		}
		pFunc(szBuffer);

		memset(szBuffer, 0, sizeof(szBuffer));
	}

	fclose(pFile);
	system("rm -f temp");
}