[英]Need to use win32 api to copy files in c# - how do I do this?
I'm trying to copy some files around, and occasionally the lengths of the names exceeds the length that the System.IO.File.Copy method can accept (260 chars according to the exception that is getting thrown)我正在尝试复制一些文件,有时名称的长度超过了 System.IO.File.Copy 方法可以接受的长度(根据抛出的异常,为 260 个字符)
According to the research I've done, I should be able to use the win32 api's file methods in conjunction with \?\ prepended to paths to get a 32,000 character limit, but I'm not sure witch methods I need to import.根据我所做的研究,我应该能够将 win32 api 的文件方法与路径前的 \?\ 结合使用以获得 32,000 个字符的限制,但我不确定我需要导入的巫术方法。
Can someone help me with this?有人可以帮我弄这个吗? I'm looking for something like (obviously a different function, but you get the idea):
我正在寻找类似的东西(显然是不同的 function,但你明白了):
[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);
[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);
http://www.pinvoke.net/default.aspx/kernel32/CopyFile.html http://www.pinvoke.net/default.aspx/kernel32/CopyFile.html
Try using CopyFile .尝试使用CopyFile 。
For PInvoke syntax, you can check pinvoke.net .对于 PInvoke 语法,您可以查看pinvoke.net 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.