當前位置: 首頁>>代碼示例>>C#>>正文


C# DirectoryInfo.IsParentOf方法代碼示例

本文整理匯總了C#中System.IO.DirectoryInfo.IsParentOf方法的典型用法代碼示例。如果您正苦於以下問題:C# DirectoryInfo.IsParentOf方法的具體用法?C# DirectoryInfo.IsParentOf怎麽用?C# DirectoryInfo.IsParentOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.IsParentOf方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Resolving_Path_If_Root_Has_Terminating_Separator_Char_Should_Work

    public void Resolving_Path_If_Root_Has_Terminating_Separator_Char_Should_Work()
    {
      root = new DirectoryInfo(@"C:\Test\");

      //test with forward and backward slashes
      Assert.IsTrue(root.IsParentOf(@"C:\Test\folder\readme.txt"));
      Assert.IsTrue(root.IsParentOf(@"C:\Test\folder\subfolder\"));

      Assert.IsTrue(root.IsParentOf(@"C:/Test/folder/readme.txt"));
      Assert.IsTrue(root.IsParentOf(@"C:/Test/folder/subfolder/"));

      root = new DirectoryInfo(@"C:\Test/");

      Assert.IsTrue(root.IsParentOf(@"C:\Test\folder\readme.txt"));
      Assert.IsTrue(root.IsParentOf(@"C:\Test\folder\subfolder\"));

      Assert.IsTrue(root.IsParentOf(@"C:/Test/folder/readme.txt"));
      Assert.IsTrue(root.IsParentOf(@"C:/Test/folder/subfolder/"));
    }
開發者ID:RainsSoft,項目名稱:UJad-AI-VFS,代碼行數:19,代碼來源:Given_Resource_When_Validating_A_Resource_Is_Descendant_Of_Root_Directory.cs

示例2: Resolving_Path_If_Test_Has_Terminating_Separator_Char_Should_Work

 public void Resolving_Path_If_Test_Has_Terminating_Separator_Char_Should_Work()
 {
   root = new DirectoryInfo(@"C:\Test");
   Assert.IsFalse(root.IsParentOf(@"C:\Test\"));
 }
開發者ID:RainsSoft,項目名稱:UJad-AI-VFS,代碼行數:5,代碼來源:Given_Resource_When_Validating_A_Resource_Is_Descendant_Of_Root_Directory.cs

示例3: Validation_Should_Work_If_Root_Is_A_Drive

 public void Validation_Should_Work_If_Root_Is_A_Drive()
 {
   root = new DirectoryInfo(@"C:\");
   Assert.IsTrue(root.IsParentOf(@"C:\Test"));
   Assert.IsFalse(root.IsParentOf(@"C:\"));
 }
開發者ID:RainsSoft,項目名稱:UJad-AI-VFS,代碼行數:6,代碼來源:Given_Resource_When_Validating_A_Resource_Is_Descendant_Of_Root_Directory.cs

示例4: Submitting_Path_Of_An_Existing_File_Should_Work

 public void Submitting_Path_Of_An_Existing_File_Should_Work()
 {
   //the validation routine internally converts the path to a directory
   //make sure this will work, even if the path links to an existing file
   FileInfo fi = new FileInfo(GetType().Assembly.Location);
   root = fi.Directory;
   Assert.IsTrue(root.IsParentOf(fi.FullName));
   Assert.IsFalse(root.IsParentOf(fi.Directory.FullName));
 }
開發者ID:RainsSoft,項目名稱:UJad-AI-VFS,代碼行數:9,代碼來源:Given_Resource_When_Validating_A_Resource_Is_Descendant_Of_Root_Directory.cs

示例5: PerformFolderOperation

    private VirtualFolderInfo PerformFolderOperation(string virtualFolderPath, string destinationPath, FileOperation operation)
    {
      if (virtualFolderPath == null) throw new ArgumentNullException("virtualFolderPath");
      if (destinationPath == null) throw new ArgumentNullException("destinationPath");

      //get folder info for source and destination, thus validating the scope of both
      string absoluteSource;
      var sourceFolder = GetFolderInfoInternal(virtualFolderPath, true, out absoluteSource);
      string absoluteDestination;
      GetFolderInfoInternal(destinationPath, false, out absoluteDestination);

      string operationName = operation == FileOperation.Move ? "move" : "copy";

      if (sourceFolder.IsRootFolder)
      {
        string msg = String.Format("Cannot {0} root folder (attempted destination: '{1}').", operationName, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceAccessException(msg);
      }

      if (String.Equals(absoluteSource, absoluteDestination, StringComparison.InvariantCultureIgnoreCase))
      {
        string msg = String.Format("Cannot {0} folder to '{1}' - source and destination are the same.", operationName, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceAccessException(msg);
      }

      var sourceDir = new DirectoryInfo(absoluteSource);
      if (sourceDir.IsParentOf(absoluteDestination))
      {
        string msg = String.Format("Cannot {0} folder '{1}' to '{2}' - destination folder is a child of the folder.", operationName, virtualFolderPath, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceAccessException(msg);
      }

      if (Directory.Exists(absoluteDestination))
      {
        string msg = "Cannot {0} folder '{1}' to '{2}' - the destination folder already exists.";
        msg = String.Format(msg, operationName, virtualFolderPath, destinationPath);
        VfsLog.Debug(msg);
        throw new ResourceOverwriteException(msg);
      }


      try
      {
        switch(operation)
        {
          case FileOperation.Move:
            Directory.Move(absoluteSource, absoluteDestination);
            break;
          case FileOperation.Copy:
            PathUtil.CopyDirectory(absoluteSource, absoluteDestination, false);
            break;
          default:
            VfsLog.Fatal("Unsupported file operation received: {0}", operation);
            throw new ArgumentOutOfRangeException("operation");
        }

        return GetFolderInfo(absoluteDestination);
      }
      catch (Exception e)
      {
        string msg = String.Format("An error occurred while trying to {0} directory '{1}' to '{2}'.",
                                          operationName, virtualFolderPath, destinationPath);
        VfsLog.Warn(e, msg);
        throw new ResourceAccessException(msg, e);
      }
    }
開發者ID:RainsSoft,項目名稱:UJad-AI-VFS,代碼行數:69,代碼來源:LocalFileSystemProvider.MoveAndCopy.cs


注:本文中的System.IO.DirectoryInfo.IsParentOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。