[問題] FindFirstFile 與 FindNextFile error

看板C_and_CPP (C/C++)作者 (Bad_To_The_Bone)時間11年前 (2014/06/25 15:05), 11年前編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ (exe run on winxp sp3, ntfs) 問題(Question): 不好意思我自己發現錯誤點了 code 在底下 要做dir的動作 http://msdn.microsoft.com/en-us/library/windows/desktop/aa364428(v=vs.85).aspx 裡面的說明是 If the function succeeds, the return value is nonzero and the lpFindFileData parameter contains information about the next file or directory found 成功=> NONZERO If the function fails, the return value is zero and the contents of lpFindFileData are indeterminate. To get extended error information, call the GetLastError function. 失敗=> ZERO 要去用GetLastError 取失敗的原因 If the function fails because no more matching files can be found, the GetLastError function returns ERROR_NO_MORE_FILES. 照理說 沒檔案時合理是 return 0 而GetLastError得到 ERROR_NO_MORE_FILES 結束 但是卻出現錯誤code 是183的奇怪現象 想請教一下可能是什麼原因 謝謝 餵入的資料(Input): 一個空目錄 (下面的output是空目錄的 如果有檔案就多點filename = "xxxx") 預期的正確結果(Expected Output): loop start filename = "." filename = ".." loop end 錯誤結果(Wrong Output): loop start filename = "." filename = ".." loop end error code = 183 程式碼(Code):(請善用置底文網頁, 記得排版) WIN32_FIND_DATA findData; HANDLE findHandle = FindFirstFile( 路徑\*.*, &findData); //print out loop start do { std::wstring fileName = findData.cFileName; //print out the filename } while (FindNextFile(findHandle, &findData) != 0); //print out loop end int error = GetLastError(); if (error != ERROR_NO_MORE_FILES) { //print out the error } 補充說明(Supplement): winerror.h 裡面 183L是 // MessageId: ERROR_ALREADY_EXISTS // Cannot create a file when that file already exists. #define ERROR_ALREADY_EXISTS 183L -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.59.147.226 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1403679954.A.5AA.html ※ 編輯: donkeychen (210.59.147.226), 06/25/2014 15:55:04 =,= 對不起 我可以自刪嗎 因為在 GetLastError前做了print log的動作 結果那個183已經不是 FindNextFile 的Error了 ※ 編輯: donkeychen (210.59.147.226), 06/25/2014 15:59:46

06/27 11:13, , 1F
orz 不能自刪..
06/27 11:13, 1F
文章代碼(AID): #1JgdJIMg (C_and_CPP)
文章代碼(AID): #1JgdJIMg (C_and_CPP)