本文整理匯總了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;
}