Esempio n. 1
0
int CmFile::GetNames(CStr &nameW, vecS &names)
{
	string dir = GetFolder(nameW);
	names.clear();
	names.reserve(6000);

	DIR *dp = opendir(_S(dir));
	if (dp == NULL){
		cout << dir << endl;
		perror("Cannot open directory");
		return EXIT_FAILURE;
	}

	struct dirent *dirContent;
	while ((dirContent = readdir(dp)) != NULL){		
		if (string(dirContent->d_name)[0] == '.')
			continue;
		struct stat st;
		lstat(dirContent->d_name,&st);
		
		if(S_ISREG(st.st_mode)){
			cout << string(dirContent->d_name) << " " << st.st_mode << endl;
			names.push_back(string(dirContent->d_name));
		}

	}

	closedir(dp);
	return (int)names.size();
}
Esempio n. 2
0
int CmFile::GetSubFolders(CStr& folder, vecS& subFolders)
{
	subFolders.clear();

	DIR *dp = opendir(_S(folder));
	if (dp == NULL){
		cout << folder << endl;
		perror("Cannot open folder");
		return EXIT_FAILURE;
	}

	struct dirent *dirContent;
	while ((dirContent = readdir(dp)) != NULL){
		if (string(dirContent->d_name)[0] == '.')
			continue;
		struct stat st;
		lstat(dirContent->d_name,&st);
		if(S_ISDIR(st.st_mode)){
			subFolders.push_back(string(dirContent->d_name));
		}

	}

	closedir(dp);
	return (int)subFolders.size();
}
Esempio n. 3
0
int CmFile::GetSubFolders(CStr& folder, vecS& subFolders)
{
	subFolders.clear();
	WIN32_FIND_DATAA fileFindData;
	string nameWC = folder + "\\*";
	HANDLE hFind = ::FindFirstFileA(nameWC.c_str(), &fileFindData);
	if (hFind == INVALID_HANDLE_VALUE)
		return 0;

	do {
		if (fileFindData.cFileName[0] == '.')
			continue; // filter the '..' and '.' in the path
		if (fileFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			subFolders.push_back(fileFindData.cFileName);
	} while (::FindNextFileA(hFind, &fileFindData));
	FindClose(hFind);
	return (int)subFolders.size();
}
Esempio n. 4
0
// Get image names from a wildcard. Eg: GetNames("D:\\*.jpg", imgNames);
int CmFile::GetNames(CStr &nameW, vecS &names, string &dir)
{
	dir = GetFolder(nameW);
	names.clear();
	names.reserve(10000);
	WIN32_FIND_DATAA fileFindData;
	HANDLE hFind = ::FindFirstFileA(_S(nameW), &fileFindData);
	if (hFind == INVALID_HANDLE_VALUE)
		return 0;

	do{
		if (fileFindData.cFileName[0] == '.')
			continue; // filter the '..' and '.' in the path
		if (fileFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			continue; // Ignore sub-folders
		names.push_back(fileFindData.cFileName);
	} while (::FindNextFileA(hFind, &fileFindData));
	FindClose(hFind);
	return (int)names.size();
}