文件完整路径超出MAX_PATH,无法用代码删除

凌乱哥 2017-11-28 08:10:44
首先声明文件确实存在且路径正确,核对了好几遍,文件完整路径如下:

C:\Users\XX\AppData\Local\Temp\ts_download\XXXXXXXXX@icloud.com
\B512771D40A2DF1FD35216E710E6204C1530D8D7\20171024\AppDomain-com.netease.cloudmusic
\Library\Application Support\321\0459d8a2-02cd-4478-9d53-f5687f29320f\shaders\src\starry_sky
\default_varying.def.sc

全长261个长度,比这长的也有,就拿它举例子


用CFile::Remove能捕获到异常:包含错误的路径


用DeleteFile函数则失败,GetLastError返回3

// MessageId: ERROR_PATH_NOT_FOUND
//
// MessageText:
//
// The system cannot find the path specified.
//
#define ERROR_PATH_NOT_FOUND 3L

而且这个文件全路径还无法用GetShortPathName获取短路径,GetLastError也是返回3
百度搜索的都是用cmd,那用代码该怎么实现删除超长路径文件
...全文
312 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
凌乱哥 2017-11-29
  • 打赏
  • 举报
回复
加了\\?\后,2个函数都可以删除了,厉害了
brk1985 2017-11-29
  • 打赏
  • 举报
回复
引用 6 楼 dingxz105090 的回复:
[quote=引用 3 楼 Saleayas 的回复:] In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
引用 4 楼 zgl7903 的回复:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. ➕一
call the Unicode version of the function and prepend "\\?\" to the path 这是指哪个函数的Unicode版本,CFile::Remove还是DeleteFile 加"\\?\"是加到前面还是后面,有没有例子[/quote] 肯定是前面,试试看
凌乱哥 2017-11-29
  • 打赏
  • 举报
回复
引用 3 楼 Saleayas 的回复:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.


引用 4 楼 zgl7903 的回复:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.

➕一


是Unicode工程,调的也是DeleteFileW,删除不了
凌乱哥 2017-11-29
  • 打赏
  • 举报
回复
引用 3 楼 Saleayas 的回复:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
引用 4 楼 zgl7903 的回复:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. ➕一
call the Unicode version of the function and prepend "\\?\" to the path 这是指哪个函数的Unicode版本,CFile::Remove还是DeleteFile 加"\\?\"是加到前面还是后面,有没有例子
brk1985 2017-11-29
  • 打赏
  • 举报
回复
引用 3 楼 Saleayas 的回复:
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
zgl7903 2017-11-29
  • 打赏
  • 举报
回复
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.

➕一
Saleayas 2017-11-28
  • 打赏
  • 举报
回复
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path.
schlafenhamster 2017-11-28
  • 打赏
  • 举报
回复
把文件名 分成 2 段, 用 前面的 来 设置 当前目录,后面 是 文件名。不知道 行不行 ?
凌乱哥 2017-11-28
  • 打赏
  • 举报
回复
补充一下,我的电脑是win10,64位 用Windows自己的删除功能或者彻底删除功能是可以直接有效删除的

16,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧