C# 是否有适用于不同System.IO API的Kernel32 API“;s
在我的应用程序中,我们需要在深度超过256个字符的情况下执行System.IO操作,在这种情况下,所有System.IO API都会失败。我们正在使用下面的APIC# 是否有适用于不同System.IO API的Kernel32 API“;s,c#,.net,C#,.net,在我的应用程序中,我们需要在深度超过256个字符的情况下执行System.IO操作,在这种情况下,所有System.IO API都会失败。我们正在使用下面的API System.IO.Path.Combine() System.IO.Path.GetDirectoryName() System.IO.Path.GetFileName() System.IO.Path.GetPathRoot() System.IO.Directory.Exists() System.IO.Directory.G
- System.IO.Path.Combine()
- System.IO.Path.GetDirectoryName()
- System.IO.Path.GetFileName()
- System.IO.Path.GetPathRoot()
- System.IO.Directory.Exists()
- System.IO.Directory.GetFiles()
- System.IO.Directory.GetDirectories()
- System.IO.Directory.CreateDirectory()
谢谢你。但你可能不想用它。uhttp://www.pinvoke.net/default.aspx/kernel32.CreateDirectoryEx如果使用Unicode版本,它最多支持32767个字符 与可用于创建目录的函数相同 因此,我建议您只需找到合适的函数,然后确保您使用的是Unicode版本 例如,我想可以替换
存在的。并将其与相结合,以获得GetFiles
和GetDirectories
您可能找不到Combine
的替代品,因为我认为这是一个特定于.Net的助手,但另一方面,您应该能够非常轻松地编写自己的替代品。BCL团队博客上有一个关于长路径的系列文章:
书中充斥着如何使用Win32 API处理长文件名的示例,以及对可能遇到的问题和陷阱的大量解释。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);
}