当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.GetParentDirectory方法代码示例

本文整理汇总了C#中System.IO.FileInfo.GetParentDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.GetParentDirectory方法的具体用法?C# FileInfo.GetParentDirectory怎么用?C# FileInfo.GetParentDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了FileInfo.GetParentDirectory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load_with_absolute_path_uses_correct_method

        public void Load_with_absolute_path_uses_correct_method()
        {
            // Arrange
              var thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
              var thisAssemblyFile = new FileInfo(thisAssemblyPath);
              var thisAssemblyDir = thisAssemblyFile.GetParentDirectory();
              var absPath = Path.Combine(thisAssemblyDir.FullName, "Foo.dll");

              // Act
              _sut.Object.Load(absPath);

              // Assert
              _sut.Verify(x => x.LoadAbsolute(It.IsAny<string>()), Times.Once());
              _sut.Verify(x => x.LoadRelative(It.IsAny<string>()), Times.Never());
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:15,代码来源:TestPluginAssemblyLoader.cs

示例2: GetOutputStream

        private Stream GetOutputStream(FileInfo outputFile)
        {
            var parentDir = outputFile.GetParentDirectory();
              if(!parentDir.Exists)
              {
            parentDir.CreateRecursively();
              }

              return outputFile.Open(FileMode.Create);
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:10,代码来源:RenderingJob.cs

示例3: PerformTestRun

        protected bool PerformTestRun(FileInfo sourceDocument,
                                  FileInfo expectedResultDocument)
        {
            bool output = false;
              IZptDocument document = null;
              string expectedRendering, actualRendering = null;
              bool exceptionCaught = false;

              try
              {
            document = _documentFactory.CreateDocument(sourceDocument);
              }
              catch(Exception ex)
              {
            _logger.ErrorFormat("Exception caught whilst loading the source document:{0}{1}{2}",
                            expectedResultDocument.Name,
                            Environment.NewLine,
                            ex);
            exceptionCaught = true;
              }

              if(!exceptionCaught)
              {
            using(var stream = expectedResultDocument.OpenRead())
            using(var reader = new StreamReader(stream))
            {
              expectedRendering = reader.ReadToEnd();
            }

            try
            {
              var rootDir = sourceDocument.GetParentDirectory().GetParentDirectory();
              var options = GetRenderingSettings(this.CreateTestEnvironment(rootDir));

              actualRendering = this.Render(document, options);
              output = (actualRendering == expectedRendering);
            }
            catch(Exception ex)
            {
              _logger.ErrorFormat("Exception caught whilst processing output file:{0}{1}{2}",
                              expectedResultDocument.Name,
                              Environment.NewLine,
                              ex);
              output = false;
              exceptionCaught = true;
            }
              }

              if(!output && !exceptionCaught)
              {
            _logger.ErrorFormat("Unexpected rendering whilst processing expected output:{0}{1}{2}",
                            expectedResultDocument.Name,
                            Environment.NewLine,
                            actualRendering);
              }

              return output;
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:58,代码来源:IntegrationTestBase.cs

示例4: TestGetParent

 public void TestGetParent()
 {
   DirectoryInfo currentDir = new DirectoryInfo(System.Environment.CurrentDirectory);
   FileInfo file = new FileInfo(currentDir.FullName + Path.DirectorySeparatorChar + "testFile.txt");
   
   Assert.AreEqual(currentDir,
                   file.GetParentDirectory(),
                   "File");
   Assert.AreEqual(currentDir.Parent,
                   currentDir.GetParentDirectory(),
                   "Directory");
   Assert.IsNull(currentDir.Root.GetParentDirectory(), "Filesystem root");
 }
开发者ID:csf-dev,项目名称:CSF.Core,代码行数:13,代码来源:TestFileSystemInfoExtensions.cs


注:本文中的System.IO.FileInfo.GetParentDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。