5

ERROR_FILE_NOT_FOUND当我尝试打开一个不存在但现在fopen()失败并GetLastError()返回的文件时,我通常会得到ERROR_PATH_NOT_FOUND.

那么ERROR_FILE_NOT_FOUND和 和有什么不一样ERROR_PATH_NOT_FOUND

4

3 回答 3

11

WinError.h中,ERROR_FILE_NOT_FOUND有描述性文本“系统找不到指定的文件”。并ERROR_PATH_NOT_FOUND具有描述性文本“系统找不到指定的路径”。

这并没有特别澄清问题。

但是,通常“找不到文件”是指找不到文件本身的情况,“找不到路径”是指找不到路径的组成部分(指定的目录名称之一)的情况。

于 2012-03-07T10:05:35.880 回答
6

Actually, the canonical meaning could be deduced from the names of the error codes.

The specific meaning, as it is with all "generic" error codes, highly depends on the implementation of the function that is said to "produce" this error. For an even worse example in this respect, consider the error ERROR_INVALID_DATA - only the documentation of the function could tell what should be ment by it.

This brings us to the point that fopen does not even (officially) return or set those error codes. fopen is part of the CRT library and is thus documented to use the error reporting mechanism thereof: errno.

Looking at the implementation of fopen in the CRT source code, you can see (ultimately, it is quite a callstack of internal helper functions), that fopen in the end calls (not surprisingly) the CreateFile Win32 API. It then carefully maps the errors potentially returned by CreateFile to errno-like errors (using the internal _dosmaperr() function, if you still want to follow in the CRT sources). This maps both ERROR_FILE_NOT_FOUND and ERROR_PATH_NOT_FOUND to the errno ENOENT.

So in the context of fopen the distinction is best considered meaningless as it is an implementation detail of fopen.

于 2012-03-07T10:26:27.060 回答
3

ERROR_PATH_NOT_FOUND表示容器目录不存在。 ERROR_FILE_NOT_FOUND表示容器目录存在,并且不包含命名文件。

于 2012-03-07T10:12:13.777 回答