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); }
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); }
/* /// <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; }