Delphi:如何检查文件是否存在(路径超过255个字符) [英] Delphi : how to check if a file exists (path over 255 characters)
问题描述
我需要使我的delphi应用程序能够检查当路径超过255个字符时,使用Robocopy复制的文件是否存在。
我已经尝试了通常的If FileExists(MyFile)then ...,但它总是返回false,即使文件在那里。
I need to make my delphi app able to check if a file copied using Robocopy is there or not when its path exceeds 255 characters. I have tried the usual "If FileExists(MyFile) then ... " but it always returns "false" even if the file is there.
我也试图获取文件的日期,但我得到1899/12/30这可以被认为是一个空的日期。
I also tried to get the file's date but I get 1899/12/30 which can be considered as an empty date.
文件搜索也不返回任何东西。 p>
A File search does not return anything either.
推荐答案
使用 \\?\
将文件名称为前缀扩展长度路径解析。例如,如果FileExists('\\?\'+ FileName)然后
,您将写入
Prefix the file name with \\?\
to enable extended-length path parsing. For example you would write
if FileExists('\\?\'+FileName) then
....
请注意,这只有在您调用Unicode版本的Win32 API函数时才有效。所以如果你使用Unicode Delphi,那么这样做就可以了。否则,您必须转载自己的版本的 FileExists
,该版本调用Unicode版本的API函数。
Note that this will only work if you are calling the Unicode versions of the Win32 API functions. So if you use a Unicode Delphi then this will do the job. Otherwise you'll have to roll your own version of FileExists
that calls Unicode versions of the API functions.
这些问题在MSDN上有很大的讨论:命名文件,路径和命名空间。
These issues are discussed in great length over on MSDN: Naming Files, Paths, and Namespaces.
这篇关于Delphi:如何检查文件是否存在(路径超过255个字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!