當前位置: 首頁>>代碼示例>>C#>>正文


C# DirectoryInfo.EnsureDirectoryExists方法代碼示例

本文整理匯總了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);
        }
開發者ID:ChuangYang,項目名稱:Z.ExtensionMethods,代碼行數:26,代碼來源:FileInfo.RenameFileWithoutExtension.cs

示例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;
        }
開發者ID:Nucs,項目名稱:nlib,代碼行數:20,代碼來源:DistributionManager.cs


注:本文中的System.IO.DirectoryInfo.EnsureDirectoryExists方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。