[C#]C#移动文件报错完全限定文件名必须少于 260 个字符,并且目录名必须少于 248 个字符
C#使用File.Move会报错:
错误信息:The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. 大概的意思就是:指定的路径或文件名太长,或者两者都太长。完全限定文件名必须少于 260 个字符,并且目录名必须少于 248 个字符。
上网查了很多资料不是改api就是加"\\?\"全部没有什么用,最后解决方法是:
下载这个库DLL引用
GitHub - UweKeim/ZetaLongPaths: A .NET library to access files and directories with more than 260 characters length.
引入到自己项目中,然后将
File.Move(srcpath,destpath);
换成
ZlpIOHelper.MoveFile(srcpath,destpath);
搞定!