看板 C_and_CPP 關於我們 聯絡資訊
我是使用vc++ ,win XP 我想寫一個可以讀取指定資料夾中所有檔案檔名的程式 參考之前的文章寫了一個程式如下 可是name="c:*.*"會失敗(會顯示此project資料夾中的檔案 而非c:下的檔案) 但name="e:*.*" or "d:*.*" 或是其他不是在c槽之下的資料夾都會成功 請問我的問題是出在哪裡阿 #include <stdio.h> #include <windows.h> int main() { HANDLE hFindFile; WIN32_FIND_DATA FindFileData; char *name="c:*.*"; hFindFile = FindFirstFile(name, &FindFileData); if (hFindFile==INVALID_HANDLE_VALUE) { printf("find no file\n"); } else { printf("file found\n"); printf("%s\n",&FindFileData.cFileName); } bool bResult = false; char szbuf[100][100] = {0}; int i = 0; while(!bResult) { if (!FindNextFile(hFindFile, &FindFileData)) { bResult = true; system("pause"); return 0; } printf("%s %d\n",&FindFileData.cFileName,i); i++; } system("pause"); return 0; } --
lanbert:你有權利情緒化04/19 02:07
jujang: 傑不一定要堅強04/19 02:10
bg784533: 但有些事情不能偽裝04/19 02:38
wDang: 像五樓射在04/19 02:59
DDRMIX:一二三四樓臉上04/19 03:21
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.124.43.177
VictorTom:c:\\*.* 04/29 19:29
VictorTom:C:*.*會找到目前C:的current folder, 以你的case就會看 04/29 19:30
VictorTom:到project start-up的工作目錄(所以合理推測你的程式是 04/29 19:30
VictorTom:存在C:....XD) D/E:算是運氣好對了, 保險起見還是用 04/29 19:31
VictorTom:"D:\\*.*" 比較好:) 04/29 19:32
VictorTom:PS. C:\ 才是C的根目錄; 因為放在""裡所以寫 "C:\\*.*" 04/29 19:33
evilkiss:謝謝V大 04/29 19:42
VictorTom:不客氣XD 04/29 19:52