简体   繁体   English

排除目录中的子文件夹 C#

[英]Exclude Sub Folder Within Directory C#

I wanted to exclude a folder within directory when copying the directory to other location could anyone please help me out ?将目录复制到其他位置时,我想排除目录中的文件夹,有人可以帮我吗?

string logZipTarget = "PangaeaLogs_Fail_" + currentLocation + "_" + classID + "_" + tracer + "_" +

DateTime.Now.ToString("ddMMMyyyy-HH-mm-ss", System.Globalization.CultureInfo.InvariantCulture) + ".zip";

string buildTypeFile = @"C:\build.typ";

string journalFile = @"C:\Mavis\" + tracer + ".ejl";

string logsPath = @"C:\Pangaea\PangaeaFinancialLogs\"; //Path to copy directory to

File.Copy(buildTypeFile, logsPath + "build.typ", true);

File.Copy(journalFile, logsPath + tracer + ".ejl", true);                

Helper.DirectoryCopy(@"C:\Program Files\NCR\Pangaea\", logsPath, true);

executor.ZipFolder(logsPath, logZipTarget);

Inside this location C:\\Pangaea\\PangaeaFinancialLogs\\ApplicationData i wanted to remove this folder SessionBackup but what is happening is it is copyin all the folders inside this location string logsPath = @"C:\\Pangaea\\PangaeaFinancialLogs\\";在这个位置C:\\Pangaea\\PangaeaFinancialLogs\\ApplicationData我想删除这个文件夹SessionBackup但发生的事情是它复制了这个位置字符串 logsPath = @"C:\\Pangaea\\PangaeaFinancialLogs\\";

From the bit of code provided in your comment I can only assume which classes your using.从您的评论中提供的一些代码来看,我只能假设您使用的是哪些类。 If I'm correct this should do the trick:如果我是对的,这应该可以解决问题:

    DirectoryInfo currentFolder = new DirectoryInfo("");
    String NameOfFolderNotToInclude = "";

    if(currentFolder.Name != NameOfFolderNotToInclude) 
    {
        File.Copy(newPath, newPath.Replace(@"\\xxx\yyy", @"C:\bbb"), true);
    }

Always keep in mind that equals ( MSDN ) if not overidden will always compare the actual objects for equality.请始终记住,如果未覆盖,则等于 ( MSDN ) 将始终比较实际对象的相等性。 In your case a string will never be the same as a DirectoryInfo and thus not be equal even if the DirectoryInfo is pointing at the location the string describes.在您的情况下,字符串永远不会与 DirectoryInfo 相同,因此即使 DirectoryInfo 指向字符串描述的位置也不相等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM