我正在尝试复制一些文件,偶尔名称的长度超过System.IO.File.Copy方法可以接受的长度(260个字符根据被抛出的异常)
根据我所做的研究,我应该能够将win32 api的文件方法与\?\ prepended to path一起使用以获得32,000个字符的限制,但我不确定我需要导入的方法.
有人可以帮我弄这个吗?我正在寻找类似的东西(显然是一个不同的功能,但你明白了):
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern SafeFileHandle CreateFileW(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
Run Code Online (Sandbox Code Playgroud)
[DllImport("kernel32.dll",
CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool CopyFile(
[MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName,
[MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName,
[MarshalAs(UnmanagedType.Bool)] bool bFailIfExists);
Run Code Online (Sandbox Code Playgroud)
http://www.pinvoke.net/default.aspx/kernel32/CopyFile.html