Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.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# 目录类对象是否缓存信息?_C#_Directory_Share - Fatal编程技术网

C# 目录类对象是否缓存信息?

C# 目录类对象是否缓存信息?,c#,directory,share,C#,Directory,Share,我的印象是,目录类方法GetDirectories()和Exists()总是获取目录中的当前情况。但不知何故,对于文件共享来说,情况似乎并非如此 我正在修复一个复杂的后台服务,它自动将文件从本地目录复制到共享。只要我不接触共享中的文件,一切都正常 出于某种原因,当我删除目标共享中的文件时,GetDirectories()和Exist()会告诉服务它们已经在那里了,但是没有 下面的代码是一个递归例程,它以与源目录相同的顺序创建目标目录。但有时就是没有。我已经测试了确定某些条件的正则表达式,并得出结

我的印象是,目录类方法GetDirectories()和Exists()总是获取目录中的当前情况。但不知何故,对于文件共享来说,情况似乎并非如此

我正在修复一个复杂的后台服务,它自动将文件从本地目录复制到共享。只要我不接触共享中的文件,一切都正常

出于某种原因,当我删除目标共享中的文件时,GetDirectories()和Exist()会告诉服务它们已经在那里了,但是没有

下面的代码是一个递归例程,它以与源目录相同的顺序创建目标目录。但有时就是没有。我已经测试了确定某些条件的正则表达式,并得出结论,它们按预期工作,因此.Success属性之一正确无误。这不是它失败的地方。路径也不包含“Quant…”字符串。因此,它应该始终创建目录

我试着在本地复制,但不能。只有在从目标共享中删除文件后,才会在生产服务器上执行此操作

我能得出的唯一结论是,共享的目录信息被缓存在某个地方。如果我停止服务,请删除文件并重新启动服务。一切都很完美。如果在服务运行时删除文件,则在复制过程中会崩溃,但出现以下异常:

找不到路径的一部分 “\\wur\dfs root\PROJECTS\ESG\u ERA\u GLP\D0154234\1\NONGLP\2020\cpf\2020.okt26\cpf001.d\AcqData CumulativeAuditTrail.xml”

因为未创建部分directorystructure。如果我在目标中查找,则尚未创建以“2020.okt26”开头的目录

        private void CreateFolders(string sourcePath, string destinationPath)
        {
            foreach (string dirPath in Directory.GetDirectories(sourcePath))
            {
                try
                {
                    var destFolder = (destinationPath + dirPath.Remove(0, _sourceRootFolder.Length));

                    if (!destFolder.HasRootLocks(destinationPath))
                    {
                        Match isGlpFolder = glpFolders.Match(dirPath);
                        Match isNonGLPFolder = nonglpFolders.Match(dirPath);
                        Match isNonGLPRootFolder = destNonglpRootFolders.Match(destFolder);
                        Match isGLPRootFolder = destGlpRootFolders.Match(destFolder);

                        destFolder = (destinationPath + dirPath.Remove(0, _sourceRootFolder.Length));

                        if ((isGlpFolder.Success || isNonGLPFolder.Success)
                            && !dirPath.Contains("QuantResults")
                            && !dirPath.Contains("QuantReports"))
                        {
                            if (!Directory.Exists(destFolder))
                            {
                                var di = Directory.CreateDirectory(destFolder);

                                if (isGLPRootFolder.Success)
                                {
                                    SetDirSec(destFolder, glpAccessRule, true);
                                }

                                if (isNonGLPRootFolder.Success)
                                {
                                    SetDirSec(destFolder, nonglpAccessRule, true);
                                }
                            }
                            Match isQuantFolder = quantFolders.Match(destFolder);

                            if (isGlpFolder.Success && isQuantFolder.Success)
                            {
                                Directory.CreateDirectory($"{destFolder}\\QuantResults");
                                Directory.CreateDirectory($"{destFolder}\\QuantReports");
                            }
                        }
#if EXTRAINFO
                        else
                        {
                            Log.Info($"Did not create folder: {destFolder} GLP?:{isGlpFolder.Success} NONGLP?:{isNonGLPFolder.Success}");
                        }
#endif
                    }
                    CreateFolders(dirPath, destinationPath);
                }
                catch (UnauthorizedAccessException ex)
                {
                    _glpDebugger.DebugMessage($"Fout bij folder {dirPath}. Error: {ex.Message}", true, true, false);
                    Log.Info($"CreateFolders: {ex.MessageEx()}");
                    continue;
                }
                catch (Exception ex)
                {
                    _glpDebugger.DebugMessage($"Fout bij folder {dirPath}. Error: {ex.Message}", true, true, false);
                    Log.Info($"CreateFolders: {ex.MessageEx()}");
                    continue;
                }
                finally
                {
                    //continue on error
                }
            }
        }

网络路径。。。我不认为是.net缓存了数据,更有可能是Windows缓存了数据。是的,这也是可能的。有办法刷新这个缓存吗?