maoyehu 1 год назад
Родитель
Сommit
0f90a9c18c
1 измененных файлов с 52 добавлено и 20 удалено
  1. 52 20
      MFCApplication1/MFCApplication1Dlg.cpp

+ 52 - 20
MFCApplication1/MFCApplication1Dlg.cpp

@@ -387,35 +387,67 @@ enum EnumSearFileType {
 	dir,//扫描文件夹
 };
 
+//void GetImages(CString strPath)
+//{
+//	queue<CString>	queuePath;
+//	queuePath.push(strPath);
+//	EnumSearFileType serchType = file;
+//	CFileFind finder;
+//	do
+//	{
+//		bool bFinished = finder.FindFile(queuePath.front() + _T("\\*.JPG"));
+//		while (serchType == file && bFinished)
+//		{
+//			bFinished = finder.FindNextFile();
+//			if (finder.IsDirectory())continue;
+//			CString strPath = finder.GetFilePath();
+//			g_vecFileList.push_back(UnicodeToGB2312(strPath));
+//		}
+//		serchType = dir;
+//		bFinished = finder.FindFile(queuePath.front() + _T("\\*.*"));
+//		while (bFinished)
+//		{
+//			bFinished = finder.FindNextFile();
+//			if (finder.IsDirectory() && !finder.IsDots())
+//			{
+//				queuePath.push(finder.GetFilePath());
+//			}
+//		}
+//		queuePath.pop();
+//		serchType = file;
+//	} while (queuePath.size() > 0);
+//}
+
 void GetImages(CString strPath)
 {
-	queue<CString>	queuePath;
-	queuePath.push(strPath);
-	EnumSearFileType serchType = file;
+	strPath += "\\*.*";
 	CFileFind finder;
-	do
+	BOOL ret = finder.FindFile(strPath);
+	while (ret)
 	{
-		bool bFinished = finder.FindFile(queuePath.front() + _T("\\*.JPG"));
-		while (serchType == file && bFinished)
+		ret = finder.FindNextFile();
+		if (finder.IsDots())
 		{
-			bFinished = finder.FindNextFile();
-			if (finder.IsDirectory())continue;
-			CString strPath = finder.GetFilePath();
-			g_vecFileList.push_back(UnicodeToGB2312(strPath));
+			continue;
 		}
-		serchType = dir;
-		bFinished = finder.FindFile(queuePath.front() + _T("\\*.*"));
-		while (bFinished)
+		else if (finder.IsDirectory())
+		{
+			CString nextPath = finder.GetFilePath();
+			GetImages(nextPath);
+		}
+		else
 		{
-			bFinished = finder.FindNextFile();
-			if (finder.IsDirectory() && !finder.IsDots())
+			CString fileName = finder.GetFileName();
+			fileName.MakeLower();
+			if (fileName.Find(L".jpg") != -1 || fileName.Find(L".jpeg") != -1 || fileName.Find(L".tif") != -1 || 
+				fileName.Find(L".tiff") != -1 || fileName.Find(L".png") != -1)
 			{
-				queuePath.push(finder.GetFilePath());
+				g_vecFileList.push_back(UnicodeToGB2312(finder.GetFilePath()));
 			}
 		}
-		queuePath.pop();
-		serchType = file;
-	} while (queuePath.size() > 0);
+	}
+
+	finder.Close();
 }
 
 string GetBatchId()
@@ -527,7 +559,7 @@ END_MESSAGE_MAP()
 BOOL CMFCApplication1Dlg::OnInitDialog()
 {
 	CDialogEx::OnInitDialog();
-	
+
 	// 将“关于...”菜单项添加到系统菜单中。
 
 	// IDM_ABOUTBOX 必须在系统命令范围内。