2010-11-11 36 views
5

在我的應用程序中,我們要求必須在深度超過256個字符的System.IO操作上進行操作,在這種情況下,所有System.IO API都會失敗我們使用下面的API。是否有針對不同System.IO API的Kernel32 API「S

  • System.IO.Path.Combine()
  • System.IO.Path.GetDirectoryName()
  • System.IO.Path.GetFileName()
  • 系統.IO.Path.GetPathRoot()
  • System.IO.Directory.E xists()
  • System.IO.Directory.GetFiles()
  • System.IO.Directory.GetDirectories()
  • System.IO.Directory.CreateDirectory()

請指引我,如果有任何替代上述API的使用,這將超過256個字符的工作,

謝謝

回答

0

PI調用。但是你可能不想使用它。 uhttp://www.pinvoke.net/default.aspx/kernel32.CreateDirectoryEx

0

如果您使用Unicode版本的GetFullPathName它最多支持32,767個字符。

CreateFile函數一樣,可以用來創建目錄。

所以我建議找到合適的功能數量爲File Management Functions,然後確保您使用的是Unicode版本。

例如,FindFirstFile可能會取代Exists我想。並與FindNextFile結合起來,因爲我認爲這是一個.Net的幫手,但在另一方面,你應該能夠編寫自己得到的GetFilesGetDirectories

的功能你可能找不到Combine更換更換相當容易。

3

有一個在BCL團隊博客一個偉大的系列賽對於長的路徑:

它充斥着如何使用示例用於處理長文件名的Win32 API,如同w就像你可以遇到的問題和陷阱的大量解釋一樣。 DeleteFile API的一個示例:

// Taken from "Part 2" of the BCL Team Blog 
using System; 
using System.Runtime.InteropServices; 

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] 
[return: MarshalAs(UnmanagedType.Bool)] 
internal static extern bool DeleteFile(string lpFileName); 

public static void Delete(string fileName) 
{ 
    string formattedName = @"\\?\" + fileName; 
    DeleteFile(formattedName); 
}