怎麼用c語言實現遍歷某目錄或資料夾裡的所有檔案(所有型別的檔案)?

時間 2021-07-10 10:58:12

1樓:石峻峰

手邊正好有C++的實現,先貼乙個,還是比較接近的把std::string改為char* ,std::vector改為char**

基本就是C語言了

#include

#include

#include

#include

void

__GetFiles

(std

::string

path

,std

::vector

string

>&files

)else

}while

(_findnext

(hFile,&

fileinfo)==

0);_findclose

(hFile);}

}std

::vector

string

>GetFiles

(std

::string

path

)using

namespace

std;

intmain()

2樓:傻哈哈frozen

DIR *d = opendir(argv[1]);

struct dirent *entry = NULL;

if (!d)

else

{for (entry = readdir(d); entry != NULL; entry = readdir(dif (!strcmp(entry->d_name, "."))

continue;

if (!strcmp(entry->d_name, ".."))continue;

if (DT_REG == entry->d_typeif (entry->d_name[0] == '.')

continue;

printf("list file [%s]\n", entry->d_nameelseprintf("file [%s] is %d\n", entry->d_name, entry->d_type

c語言實現能否儲存資料?

我來補充一點吧。很多回答說到了檔案讀寫,這是對的,但是乙個應用程式儲存資料到硬碟也有主流的三種方式 1,使用自己設計的檔案格式,就比如說樓上有些回答直接把乙個變數的值寫進檔案,下次開啟程式直接讀檔案來得知上次執行的結果。2,使用 XML,JSON,INI 等檔案格式。其實這些檔案格式說到底還是純文字...

請問雙緩衝區c語言實現?

我就是這麼拽 include include include include include include include include using namespace std DWORD WINAPI Fun1 LPVOID lpParameter DWORD WINAPI Fun2 LPVO...

有沒有用C語言實現不了的程式?

我是半吊子。不過,大學學彙編時候,老師說如果某個程式需要非常標準的時間的時候,不能用c語言,因為c的每條指令執行時間不是固定的。這個時候就要用到彙編 學渣,只接觸過這兩種語言,不知別的是否可以 因為組合語言中每條指令需要的時間是固定的。呃,記得是這樣,如果我記錯了一定要告訴我。 余天公升 圖靈完全是...