查找文件夾中的後綴文件

頭文件#include <io.h>
//函數調用;
string framesFolder=fasta文件的路徑;
string fileNames[10000] ;
int fileCount = 0 ;//初始值;
getFileNames( fileNames, fileCount, framesFolder ) ;//返回txt文件名fileNames;文件個數fileCount;



//函數聲明;
void getFileNames( string fileNames[], int& fileCount, string imgFolder, string subFolderPath = "" );

//函數定義;
void getFileNames( string fileNames[], int& fileCount, string imgFolder, string subFolderPath )
{
	struct _finddata_t filefind ;
	intptr_t handle ;
	string foldPath = imgFolder + "*.txt" ;

	if ( ( handle = _findfirst( foldPath.c_str(), &filefind ) ) == -1L ) return ;

	do 
	{
		if ( filefind.attrib & _A_SUBDIR)    
		{
			if( (strcmp(filefind.name,".") != 0 ) &&(strcmp(filefind.name,"..") != 0))   
			{
				subFolderPath = filefind.name ; 
				subFolderPath += "\\" ;
				string newPath = imgFolder + subFolderPath ;
				getFileNames( fileNames, fileCount, newPath, subFolderPath );
			}
		}
		else
		{
			fileNames[fileCount++] = subFolderPath + filefind.name ;
		}		
	}
	while( 0 == _findnext( handle, &filefind ) ) ;
	_findclose( handle ) ;  
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章