[問題] FindFirstFile 與 FindNextFile error

作者: donkeychen (Bad_To_The_Bone)   2014-06-25 15:05:50
開發平台(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
作者: donkeychen (Bad_To_The_Bone)   2014-06-27 11:13:00
orz 不能自刪..

Links booklink

Contact Us: admin [ a t ] ucptt.com