FindFirstFile / FindNextFile in Linux

Discussion of chess software programming and technical issues.

Moderator: Ras

Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

FindFirstFile / FindNextFile in Linux

Post by Edmund »

The new Glass release shall have extensive personalities features. In Windows I used the FindFirstFile / FindNextFile to look for personality files in a special folder and print them in the UCI engines dialog (therefor I need to add the files matching the pattern "*.ini" to a string). Is there a way to do this in Linux?

My current Windows function is the following:

Code: Select all

void options_find_personality(void) {
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind = INVALID_HANDLE_VALUE;

	strcpy(personality_names, "var main");

	hFind = FindFirstFile("personalities\\*.ini", &FindFileData);

	if (hFind == INVALID_HANDLE_VALUE) return;

	strcat(personality_names, " var ");
	strcat(personality_names, FindFileData.cFileName);
	personality_names[strlen(personality_names)-4] = 0;

	while(FindNextFile(hFind, &FindFileData)) {
		strcat(personality_names, " var ");
		strcat(personality_names, FindFileData.cFileName);
		personality_names[strlen(personality_names)-4] = 0;
    }
}
regards,
Edmund
User avatar
Volker Annuss
Posts: 181
Joined: Mon Sep 03, 2007 9:15 am

Re: FindFirstFile / FindNextFile in Linux

Post by Volker Annuss »

Hi Edmund,

you can use opendir() and readdir() to read a directory and do the filtering for *.ini yourself.

And there is a scandir() that helps with filtering.

Greetings
Volker
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: FindFirstFile / FindNextFile in Linux

Post by Edmund »

Volker Annuss wrote:Hi Edmund,

you can use opendir() and readdir() to read a directory and do the filtering for *.ini yourself.

And there is a scandir() that helps with filtering.

Greetings
Volker
Thanks for the instant reply Volker, I will have a look into these new functions.