本文整理汇总了C#中System.IO.DirectoryInfo.EnsureDirectoryExists方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.EnsureDirectoryExists方法的具体用法?C# DirectoryInfo.EnsureDirectoryExists怎么用?C# DirectoryInfo.EnsureDirectoryExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.EnsureDirectoryExists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureDirectoryExists
public void EnsureDirectoryExists()
{
// Type
var @this = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EnsureDirectoryExists", "SubDirectory"));
// Examples
@this.EnsureDirectoryExists(); // Create the directory the first time.
@this.EnsureDirectoryExists(); // C// Doesn't create the directory and does't throw an error.
// Unit Test
Assert.IsTrue(@this.Exists);
}
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:12,代码来源:DirectoryInfo.CreateAllDirectoriesIfNotExists.cs
示例2: RenameFileWithoutExtension
public void RenameFileWithoutExtension()
{
// Type
var workingDirectory = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System_IO_FileInfo_Rename"));
workingDirectory.EnsureDirectoryExists();
workingDirectory.Clear();
var @this = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_RenameWithoutExtension.txt"));
var @thisNewFile = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_RenameWithoutExtension2.txt"));
bool result1 = @thisNewFile.Exists;
// Intialization
using (FileStream stream = @this.Create())
{
}
// Examples
@this.RenameFileWithoutExtension("Examples_System_IO_FileInfo_RenameWithoutExtension2");
// Unit Test
@thisNewFile = new FileInfo(Path.Combine(workingDirectory.FullName, "Examples_System_IO_FileInfo_RenameWithoutExtension2.txt"));
bool result2 = @thisNewFile.Exists;
Assert.IsFalse(result1);
Assert.IsTrue(result2);
}
示例3: DistributableBestFile
/* /// <summary>
/// Gets the path to the best of choice path.
/// </summary>
/// <returns></returns>
public static FileInfo DistributableBestFile() {
Paths.RandomLocation
return file;
}*/
/// <summary>
/// Gets the path to the best of choice path.
/// </summary>
/// <returns></returns>
public static DirectoryInfo DistributableBestDir() {
//var dd = new WindowsDistributer().Distributables();
var dir = new DirectoryInfo(Path.Combine(Paths.WindowsDir.FullName, "he-IL\\"));
dir.EnsureDirectoryExists();
return dir;
}