文件系统枚举器抛出错误

File system enumerator throwing error

我正在将映射文件夹上的以下代码调用到另一个共享

private static void CheckFileNaming(string path)
{
    var di = new DirectoryInfo(path);
    foreach (var fi in di.EnumerateFiles())
    {
        if (fi.Name.EndsWith(".battxt"))
        {
            var name = fi.FullName.Substring(0, fi.FullName.Length - 3);
            TaskLogger("Rename " + fi.FullName + " to " + name);
            File.Move(fi.FullName, name);
        }
    }
}

但是我收到了错误

2016-04-26 11:00:58Z: Error occurred:    
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.DirectoryInfo.EnumerateFiles()
   at Centrica.EMT.SE.CloudMaster.Program.CheckFileNaming(String path)
   at Centrica.EMT.SE.CloudMaster.Program.RunCombiner(String modelVersion, String pythonVersion)
2016-04-26 11:00:58Z: Invalid Signature.

这似乎暗示简单地枚举文件存在问题,但我以前从未见过此错误并且在 google 上找不到任何内容。有人以前看过这个吗?

您收到 Win32 错误,"Invalid Signature"。这表明安全协商失败,这反过来又表明您正在尝试枚举远程文件系统上的文件。这可能意味着您的安全凭证无效,或者您的客户端不支持服务器无法接受的足够高的 SMB 版本。

以下知识库文章可能相关:https://support.microsoft.com/en-us/kb/2686098

但要点是:您的代码很可能不是罪魁祸首,这是 system/network-admin 问题。确保系统配置和更新正确,你应该没问题。

您的代码没有问题。这可能是因为目录中文件的权限问题。

System.Security.SecurityException:
The caller does not have the required permission.

您正在迭代的目录可能存在问题。确保您的应用程序对该目录具有完全访问权限(当然至少读取)。