c# - 目录存在在桌面与服务器上产生不一致的结果

标签 c# windows

我有一个 C# 程序,它检查特定目录是否存在。

它只是在做:

Directory.Exists(path).

我也尝试了其他方法。使用 DirectoryInfo 和使用 AlphaFS

在我的本地机器上,路径存在。当我使用相同的凭据在服务器上运行相同的程序时,它不存在。

不知道是不是组策略的问题。但我可以上一层楼看到它。

\server\volume\share\sub 目录 - 远程不存在,但在我的桌面上存在 \server\volume\share - 存在于我的桌面和远程服务器上

更新 我忘了说,因为我可以访问我的桌面,所以我得到了 ACL 信息。 所有小组都无法翻译。

我真的只是想让这个应用程序以与服务器上相同的方式运行,并找出它运行不同的原因。

更新 2 这些是物理服务器。 我的桌面是 Liquid VDI

代码如下:

 var path = txtPath.Text;
        using (var user = new Impersonation(fuserdomain, fc_user, fc_pass))
        {
            var alphaExists = Alphaleonis.Win32.Filesystem.Directory.Exists(path);
            var alphaDIExists = new Alphaleonis.Win32.Filesystem.DirectoryInfo(path).Exists;
            var SystemExists = System.IO.Directory.Exists(path);
            var SystemDIExists = new System.IO.DirectoryInfo(path).Exists;
            var AlphaHasFiles = false;
            var AlphaDIHasFiles = false;
            var SystemHasFiles = false;
            var SystemDIHasFiles = false;
            try
            {
                Directory.GetFiles(path);
                AlphaHasFiles = true;
            }
            catch {  }
            try
            {
                new DirectoryInfo(path).GetFiles();
                AlphaDIHasFiles = true;
            }
            catch {  }
            try
            {
                System.IO.Directory.GetFiles(path);
                SystemHasFiles = true;
            }
            catch { }
            try
            {
                new System.IO.DirectoryInfo(path).GetFiles();
                SystemDIHasFiles = true;
            }
            catch { }

            MessageBox.Show(string.Format("alphaExists: {0}\nalphaDIExists: {1}\nSystemExists: {2}\nSystemDIExists: {3}\nAlphaGetFiles: {4}\nAlphaDIGetFiles: {5}\nSystemGetFiles: {6}\nSystemDIGetFiles: {7}\n", alphaExists, alphaDIExists, SystemExists, SystemDIExists, AlphaHasFiles, AlphaDIHasFiles, SystemHasFiles, SystemDIHasFiles));
        }

更新 3 虽然我有解决这个问题的方法;我仍然不确定为什么我的桌面和服务器之间会有差异。有什么工具可以帮助我了解问题出在哪里吗?

最佳答案

我在 File.Exists 中也看到过同样的情况。我一直没有找到答案,最后认输了,我只是尝试使用它并捕获异常。

无论如何,可靠的代码必须捕获它,所有测试所做的就是避免在文件或目录不存在时尝试。 (而且 PITA 表明 Visual Studio 不再以任何方式忽略特定行上的异常。运行时没有问题,在开发中很烦人。)

关于c# - 目录存在在桌面与服务器上产生不一致的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48953190/

相关文章:

c# - 如何设置SqlDependency来监控多个表

c# - 使用 MSTest 和 Moq 测试存储库 - .Verify 不工作

C# 用户输入 int 到数组

windows - 程序关闭后,文件可以在 Windows 中锁定多长时间?

windows - 专为 Unix 设计的 Node.js 模块?

C# 继承硬件分配;多个家长的单一类(class)?

c# - 将平面列表映射到具有父 ID C# 的分层列表

c++ - 外部 IP 地址

windows - 子驱动器和文件夹

java - java中的命名管道