C 獲取目錄和檔案列表

2021-09-01 23:16:02 字數 1186 閱讀 8983

//獲取目錄路徑下面所有檔案的內容

//適用於linux和windows系統

#include

#include

#include

#include

#ifdef _win32

#include

#include

#else

#include

#endif

using namespace std;

////獲取指定目錄下所有檔案的檔名,不包括資料夾,在getfilefromdir中使用

//strdir: 輸入,目錄路徑

//vfiledirlist: 輸出,檔案路徑列表

//返回:空

//void getfilenamefromdir(string strdir,vector& vfiledirlist)

do

}while (findnextfilea(hfind, &ffd) != 0);

dwerror = getlasterror();

if (dwerror != error_no_more_files) 

findclose(hfind);

#else

dir *dir;

struct dirent *ptr;

dir = opendir(strdir.c_str());

while( (ptr = readdir(dir)) != null)

closedir(dir);

sort(vfiledirlist.begin(), vfiledirlist.end());

#endif}//

//獲取指定目錄下所有檔案內容

//strdir: 輸入,目錄路徑

//vfilenamelist: 輸出,檔案內容列表

//返回:空

//void getfilefromdir(string strdir,vector& vfilelist)

string line="";

string file="";

while (getline(infile,line))

vfilelist.push_back(file);}}

int main(int argc,char* argv)

else

coutreturn 0;}}

C 獲取全部目錄和檔案

public class fileaccess 獲取所有檔名 private arraylist getfilename string dirpath return list 獲取所有資料夾及子資料夾 private void getdirs string dirpath 獲取給出資料夾及其子資料夾...

PHP遍歷目錄和檔案列表

php view plain copy define ds directory separator class getdirfile closedir handle else return dirarray 獲取檔案列表 public function getfile dir closedir ha...

python目錄和檔案的列表清單

import os 通過給定的資料夾,列舉出這個資料夾當中,所有的檔案,以及資料夾,子資料夾當中的所有檔案 def listfilestotxt dir,file 1.列舉出,當前給定的資料夾,下的所有子資料夾,以及子檔案 file list os.listdir dir print file li...