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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated opening of files. 1

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
0
0
US
Say, I need to process a folder with about 50 files. Now instead of explicitly stating a name to open each file, can I just give the name of the folder and open all the files one by one in the folder, until all are done?

 
Umm...dirent.h is not available in Visual C++ 6.0. What do I do? HELP!
 
code I have used in the past :

Code:
	char* szDirName = "C:/some/dir";
	
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind = INVALID_HANDLE_VALUE;
	char DirSpec[MAX_PATH];  // directory specification
	DWORD dwError;

	strncpy (DirSpec, szDirName, strlen(szDirName)+1); 
	strncat (DirSpec, "\\*", 3);

	hFind = FindFirstFile(DirSpec, &FindFileData);

	if (hFind == INVALID_HANDLE_VALUE) {
		printf("Invalid file handle. Error is %u\n", GetLastError());
		return NULL;
	} else {
		printf("File : %s\n", FindFileData.cFileName);
	}

	dwError = GetLastError();
	FindClose(hFind);
	if (dwError != ERROR_NO_MORE_FILES) {
		printf("FindNextFile error. Error is %u\n", dwError);
		return NULL;
		}
	}

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
But...can't comprehend...whats going on? This is not a console application I guess...thats the only thing I can use. Get a zillion errors when I try to compile this.
 
That code was used in a console application.
Did you include stdio.h and windows.h ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top