获取某一目录下所有文件夹名,返回vector「string」

vector  listFiles(const char * dir)
{
	vector FolderNames;
	HANDLE hFind;
	WIN32_FIND_DATA findData;
	LARGE_INTEGER size;
	hFind = FindFirstFile(dir, &findData);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		cout << "Failed to find first file!\n";
		return FolderNames;
	}
	do
	{

		if (strcmp(findData.cFileName, ".") == 0 || strcmp(findData.cFileName, "..") == 0)
			continue;
		if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)    // 是否是目录 
		{
			string sCurFilePath = dir;
			sCurFilePath = sCurFilePath.replace(sCurFilePath.find("*.*"), 3, findData.cFileName);
			sCurFilePath = sCurFilePath + "/";
			FolderNames.push_back(sCurFilePath);
			cout << findData.cFileName << "\t\n";
		}
		else
		{
			size.LowPart = findData.nFileSizeLow;
			size.HighPart = findData.nFileSizeHigh;
			cout << findData.cFileName << "\t" << size.QuadPart << " bytes\n";
		}
	} while (FindNextFile(hFind, &findData));
	cout << "Done!\n";
	return FolderNames;
}

const char * dir = "D:/20Anonymize/*.*";

你可能感兴趣的:(C++)