gpt4 book ai didi

c++ - GetFileAttributes 因绝对路径而失败

转载 作者:搜寻专家 更新时间:2023-10-31 00:09:24 26 4
gpt4 key购买 nike

<分区>

我正在用 WinAPI 编写一个简单的程序来检查目录是否存在,这是功能代码:

BOOL directoryExists( LPCSTR path ) {
DWORD pathAttributes = GetFileAttributes ( path );

return pathAttributes != INVALID_FILE_ATTRIBUTES
&& pathAttributes == FILE_ATTRIBUTE_DIRECTORY;
}

然后我在我的 main 中用这行代码测试它:

 std::cout << ( ( directoryExists( "C:\\Users\\Admin\\Desktop" ) ?  
"Directory found" : "Directory not found" )
<< static_cast< char >( 0xA );

看起来无论我尝试输入什么绝对路径,我都会得到“找不到目录”。不管怎样,相对路径都会成功!

我哪里失败了? :|

提前致谢!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com