Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否有适用于不同System.IO API的Kernel32 API“;s_C#_.net - Fatal编程技术网

C# 是否有适用于不同System.IO API的Kernel32 API“;s

C# 是否有适用于不同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

在我的应用程序中,我们需要在深度超过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.GetFiles()
  • System.IO.Directory.GetDirectories()
  • System.IO.Directory.CreateDirectory()
请指导我,如果有任何上述API的替代品可用于256个字符以上


谢谢你。但你可能不想用它。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);
}