[问题] 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