1. 程式人生 > >win10 下 c++遍歷資料夾

win10 下 c++遍歷資料夾

主要使用#include <io.h>庫下的函式

如果 路勁控制代碼定義為long型別,_findnext函式會報 訪問異常,解決方法參考:http://blog.csdn.net/kelvin_yan/article/details/53997840


例項程式碼:

#include <fstream>
#include <string>
#include "utils.h"
#include <stdio.h>

#include <direct.h>
#include <iostream>
#include <io.h>

using namespace std;
using namespace cv;

string trainPtah = "F://vido and images fro test//UIUC texture database";

void getClassName(string path, vector<string>& paths)
{
	intptr_t hFile = 0;
	struct _finddata_t fileinfo;
	string p;

	hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo);

	if (hFile != -1) {
		while (_findnext(hFile, &fileinfo) == 0) {
			if (fileinfo.attrib & _A_SUBDIR) {
				if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
					paths.push_back(p.assign(path).append("/").append(fileinfo.name));//儲存資料夾名字
				}
			}
		}
	}
}


void main()
{
	vector<string> paths;
	getClassName(trainPtah, paths);
	for (int i = 0; i < paths.size(); i++) {
		cout << paths.at(i) << endl;
	}

	system("pause");
}


相關推薦

win10 c++資料

主要使用#include <io.h>庫下的函式 如果 路勁控制代碼定義為long型別,_findnext函式會報 訪問異常,解決方法參考:http://blog.csdn.net/kelvin_yan/article/details/53997840 例項

【筆記】window 使用c++資料及其子資料和檔案,並列印檔案路徑及各檔案內容

這兩天一直在學習如何使用c++遍歷資料夾、讀取檔案內容和寫入檔案。 話不多說,直接上程式碼 /** 檔案功能:遞迴遍歷資料夾,遍歷資料夾及其子資料夾和檔案.列印資料夾名稱、檔名稱和檔案數目*** 參考:https://www.cnblogs.com/collectionne/p/679230

C++資料所有的wav檔案(支援windows和Linux)

直接上程式碼: #include <iostream> #include <string> #include <vector> #include <fstream> #include <string.h> #includ

C++ 資料以及子資料所有檔案

CFileFind 所提供的方法進行資料夾以及子資料夾遍歷時,經過測試會出現如果當前遍歷的路徑為碟符,且碟符中僅包含一箇中文資料夾(資料夾名以漢字開頭),此時遍歷不到該資料夾。 所以採用以下方法(需要新增頭#include "io.h" ) void GetAllFile

C++資料的所有資料及檔案

問題: 給定一個資料夾,獲取資料夾下的所有檔案,並將檔案的路徑進行儲存 解決方法: 採用遞迴的思想,在遞迴過程中對每一層進行遍歷。若為資料夾,繼續向下遍歷。若為檔案,將路徑儲存。 實現程

c++ 資料的所有檔案

同樣的程式碼在VS2010中可以得到正常結果,但是VS2013中卻不行,實在想不通.. 沒有找到解決VS2013中遍歷問題的解決辦法,只好另外想辦法.然後想起C++中應該也有能夠實現資料夾遍歷的方法. 在VS2013中實踐一下: #include <s

c#資料獲得所有檔案

c#遍歷資料夾獲得所有檔案 在c#中,想要獲得一個資料夾下的所有子目錄以及檔案十分簡單。 首先,獲取目錄的情況下,DirectoryInfo.GetDirectories():獲取目錄(不包含子目錄)的子目錄,返回型別為DirectoryInfo[],支援萬用字元查詢; 其次,獲取檔案的

WIN32 C++ 資料

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

C/C++資料和檔案

庫函式 包含標頭檔案 #include 用到資料結構_finddata_t,檔案資訊結構體的指標。 struct _finddata_t { unsigned attrib; //檔案屬性 time_t time_c

C++資料中的檔案並把結果儲存到csv中

StaDir.h檔案 #pragma once #include "browsedir.h" class CStaDir : public CBrowseDir { public: CStaDir(void); ~CStaDir(void); int m_nFileCount;

c++資料內所有檔案

#include<vector> #include<string> #include<io.h> #include<iostream> using namespace std; char * filePath = "D:\\JPEGImages

C#資料下子檔案

 public  class ChooseMove     {         //遍歷資料夾         public List<string> FindFile

使用C++資料/目錄

編寫程式遍歷資料夾及其子資料夾下所有檔案,並輸出到標準輸出流或者檔案流。 先考慮在單層目錄下,遍歷所有檔案。以C:\WINDOWS為例: 用到資料結構_finddata_t,檔案資訊結構體的指標。 struct _finddata_t {

C++資料(包含子資料中的檔案)

<span style="font-size:24px;">最近因為跟著老師做專案,需要遍歷指定資料夾下的指定檔案,故在此記錄學習情況,以便以後複習使用。</span> 找了幾種方法,最後決定使用資料結構_finddata_t ,網上有太多一樣的資

C# 資料 刪除過期圖片

/// <summary> /// 刪除過期的儲存圖片 /// </summary> public void DeleteOTIm

C#資料,只需一句話

一個函式搞定,都不用去考慮遞迴(以前居然不知道),太強大了。 string[] files = System.IO.Directory.GetFiles(_dir, "*.*", System.IO.SearchOption.AllDirectories); System.

linux c語言遞迴資料所有檔案和子資料(附上替換文字檔案內容的方法)

#include <stdio.h> #include <sys/dir.h> #include <string> #include <sys/stat.h> //判斷是否為資料夾 bool isDir(const cha

AHK 資料ahk檔案並執行與刪除

folder = D:\ver_upload\new Loop, %folder%\*.ahk FileList = %FileList%%A_LoopFileTimeModified%`t%A_LoopFileName%`n Sort, FileList ;根據日期排序.從小到大 Loo

Linux資料

#include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <string.h> char *dirname="/path/"; DIR *dirfile; dirfiles

OpenCV實現資料所有檔案

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!