当前位置: 首页>>代码示例>>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;未经允许,请勿转载。