C ++ PathFileExists限制为260个字符 [英] C++ PathFileExists limited to 260 chars

查看:216
本文介绍了C ++ PathFileExists限制为260个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 MSDN PathFileExists()函数只支持filepath< 260

As per MSDN PathFileExists() function only supports filepath < 260

我想检查远程位置是否存在路径。现在法律上我可以创建一个名称为256个字母长的文件,当我添加服务器名称,总长度超过260,因此 PathFileExists()不能使用它。

I want to check if a path exists on a remote location. Now legally I can create a file whose name is 256 letters long, when I add server name to it, the total length exceeds 260 and so PathFileExists() cannot work with it.

我需要检查文件存在什么其他选项?

What other option do I have to check for file existance?

推荐答案

p>由于所有> Shell路径处理函数限制为 MAX_PATH - 1个字符,如果需要支持更长的文件名,则必须使用kernel32函数。您的选项有:

Since all Shell Path Handling Functions are limited to MAX_PATH - 1 characters you will have to use kernel32 functions instead if you need to support longer file names. Your options are:


  1. FindFirstFile

  2. CreateFile

  3. GetFileAttributes

  1. FindFirstFile
  2. CreateFile
  3. GetFileAttributes

href =http://msdn.microsoft.com/en-us/library/aa364418.aspx =nofollowtitle =FindFirstFile function> FindFirstFile 是相当直接,你需要调用< a href =http://msdn.microsoft.com/en-us/library/aa364413.aspx =nofollowtitle =FindClose function> FindClose 如果函数未返回错误代码。如果您在网络上查询文件,则会触发附加的网络往返。 CreateFile 也会触发额外的网络往返, a>你必须清除 HANDLE 调用 CloseHandle 。此外,它可能会给予错误答案

While FindFirstFile is fairly straight forward you are required to call FindClose if the function does not return an error code. This triggers an additional network round-trip if you are querying for a file on a network. The additional network round-trip is also triggered for CreateFile where you have to cleanup the HANDLE calling CloseHandle. Plus it may give the wrong answer.

剩余的选项使用 GetFileAttributes 是建议的查询文件存在的方法,如果您需要支持长于 MAX_PATH 个字符。

The remaining option to use GetFileAttributes is the suggested way to query for file existence if you need to support file names longer than MAX_PATH characters.

这篇关于C ++ PathFileExists限制为260个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆