本文整理汇总了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());
}
示例2: GetOutputStream
private Stream GetOutputStream(FileInfo outputFile)
{
var parentDir = outputFile.GetParentDirectory();
if(!parentDir.Exists)
{
parentDir.CreateRecursively();
}
return outputFile.Open(FileMode.Create);
}
示例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;
}
示例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");
}