简体   繁体   English

需要使用win32 api来复制c#中的文件 - 我该怎么做?

[英]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.

相关问题 如何在 C#/Win32 api 中找到 Windows 应用程序执行别名的目标? - How do I find the target of a Windows App Execution Alias in C#/Win32 api? 如何在C#中读取Win32 WM_MOVE lParam x,y坐标? - How do I read the Win32 WM_MOVE lParam x,y coordinates in C#? 需要AcquireCredentialsHandle win32 api函数的C#签名 - Need a C# signature for AcquireCredentialsHandle win32 api function 当我使用 Win32 API 和 P/Invoke 更改 C# WinForms ComboBox.SelectedIndex 时,如何触发 SelectedIndexChanged? - How do I make SelectedIndexChanged trigger when I change C# WinForms ComboBox.SelectedIndex using Win32 API and P/Invoke? 我是否需要释放 Win32 API 或 WindowInteropHelper 获得的 IntPtr 句柄 - Do I need to free IntPtr handle aquired by Win32 API or WindowInteropHelper 如何在c#中禁用磁盘缓存,请使用FILE_FLAG_NO_BUFFERING调用win32 CreateFile api - how do disable disk cache in c# invoke win32 CreateFile api with FILE_FLAG_NO_BUFFERING 如何使用动作委托参数方法将Win32应用程序中C ++方法的地址传递给ac#方法 - How do I pass the address of a c++ method in win32 app to a c# method with Action delegate parameter method 如何使用C#拦截Win32 API调用? - How to intercept Win32 API calls with C#? 如何在C#中自动引入Win32 API声明? - How to automatically pull in Win32 API declarations in C#? 为什么我把win32 intptr转换成c# int数组,数据不对 - Why do I convert win32 intptr to c# int array, data is wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM