簡體   English   中英

需要使用win32 api來復制c#中的文件 - 我該怎么做?

[英]Need to use win32 api to copy files in c# - how do I do this?

我正在嘗試復制一些文件,有時名稱的長度超過了 System.IO.File.Copy 方法可以接受的長度(根據拋出的異常,為 260 個字符)

根據我所做的研究,我應該能夠將 win32 api 的文件方法與路徑前的 \?\ 結合使用以獲得 32,000 個字符的限制,但我不確定我需要導入的巫術方法。

有人可以幫我弄這個嗎? 我正在尋找類似的東西(顯然是不同的 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

嘗試使用CopyFile

對於 PInvoke 語法,您可以查看pinvoke.net

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM