当前位置: 首页>>代码示例>>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;未经允许,请勿转载。