当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.Clear方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Clear方法的具体用法?C# DirectoryInfo.Clear怎么用?C# DirectoryInfo.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.Clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildGalleryOutput

        public static CuratedGallery BuildGalleryOutput(int id)
        {
            lock (GetGallerySyncRoot(id))
            {
                CuratedGallery gallery = GetGallery(id);

                if (gallery == null)
                    throw new Exception(string.Format("Gallery with id='{0}' was not found", id));

                var outputDir = new DirectoryInfo(GalleryRuntime.GetGalleryOutputPath(id));

                if (outputDir.Exists)
                {
                    outputDir.Clear();
                }
                else
                {
                    outputDir.Create();
                }

                BuildOutput(new DirectoryInfo(GalleryRuntime.GetTemplatePath(gallery.TemplateID)), outputDir, GetGallerySourcePath(id));

                return gallery;
            }
        }
开发者ID:spbuksh,项目名称:CuratedGalleries,代码行数:25,代码来源:GalleryRuntime.Gallery.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: CreateZipFile

        public void CreateZipFile()
        {
            var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile"));
            var dir2 = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile_Zip"));

            if (dir.Exists)
            {
                dir.Clear();
            }
            if (dir2.Exists)
            {
                dir2.Clear();
            }

            // Type
            var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile", "Examples_System_IO_FileInfo_CreateZipFile.txt"));
            var zip = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CreateZipFile_Zip", "Examples_System_IO_FileInfo_CreateZipFile.zip"));

            Directory.CreateDirectory(@this.Directory.FullName);
            Directory.CreateDirectory(zip.Directory.FullName);

            // Intialization
            using (FileStream stream = @this.Create())
            {
            }

            // Examples
            @this.Directory.CreateZipFile(zip);

            // Unit Test
            Assert.IsTrue(zip.Exists);
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:32,代码来源:FileInfo.CreateZipFile.cs

示例4: Clear

        public void Clear()
        {
            // Type
            var @this = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DirectoryInfo_Clear"));
            Directory.CreateDirectory(@this.FullName);
            @this.CreateSubdirectory("FizzBuzz");
            int result1 = @this.GetDirectories().Length;

            // Exemples
            @this.Clear(); // Remove all file and directory in this directory

            // Unit Test
            int result2 = @this.GetDirectories().Length;
            Assert.AreEqual(1, result1);
            Assert.AreEqual(0, result2);
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:16,代码来源:DirectoryInfo.Clear.cs

示例5: Clear

 public void Clear()
 {
     var dir = new DirectoryInfo("abc");
     var subdir = dir.GetDirectory("test2");
     subdir.Create();
     using (var fs = new FileStream(subdir.GetFile("test3.txt").FullName, FileMode.Create)) {
         fs.WriteByte(1);
     }
     dir.Clear();
     Assert.That(dir.Exists, Is.True);
     Assert.That(dir.SafeClear(), Is.True);
     Assert.That(dir.SafeDelete(), Is.True);
     dir.Refresh();
     Assert.That(dir.Exists, Is.False);
     Assert.That(dir.SafeClear(), Is.False);
 }
开发者ID:exKAZUu,项目名称:Paraiba,代码行数:16,代码来源:DirectoryInfoExtensionsTest.cs

示例6: CreateZipFile

        public void CreateZipFile()
        {
            var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory"));
            var dir2 = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Zip"));
            var dir3 = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Output"));

            if (dir.Exists)
            {
                dir.Clear();
            }
            if (dir2.Exists)
            {
                dir2.Clear();
            }
            if (dir3.Exists)
            {
                dir3.Clear();
            }

            // Type
            var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory", "Examples_System_IO_FileInfo_ExtractZipFileToDirectory.txt"));
            var zip = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Zip", "Examples_System_IO_FileInfo_ExtractZipFileToDirectory.zip"));
            var output = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExtractZipFileToDirectory_Output"));

            Directory.CreateDirectory(@this.Directory.FullName);
            Directory.CreateDirectory(zip.Directory.FullName);
            Directory.CreateDirectory(output.FullName);

            // Intialization
            using (FileStream stream = @this.Create())
            {
            }
            @this.Directory.CreateZipFile(zip);

            var file = output.GetFiles();
            // Examples
            Assert.AreEqual(0, output.GetFiles().Length);
            zip.ExtractZipFileToDirectory(output);

            // Unit Test
            Assert.AreEqual(1, output.GetFiles().Length);
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:42,代码来源:FileInfo.ExtractZipFileToDirectory.cs

示例7: CachedFileGenerator

        public CachedFileGenerator(CachedFileGeneratorBase.Arguments Arguments, bool UnqualifiedEnvironment = false)
            : base(Arguments)
        {
            // http://stackoverflow.com/questions/867485/c-getting-the-path-of-appdata
            // http://support.microsoft.com/kb/2600217#UpdateReplacement

            var CommonApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            var Version = Environment.Version.ToString();

            if (UnqualifiedEnvironment)
            {
                Version = Version.TakeUntilLastIfAny(".");
            }

            var CacheFolder = new DirectoryInfo(
                Path.Combine(
                    CommonApplicationData,
                    "jsc/"
                    + "cache/"
                    + Version
                    + "/"
                    + this.ConstructorArguments.AssamblyFile.Name
                    + "/"
                    + this.ConstructorArguments.Language.ToString()
                )
            );


            // next new cache name
            var Cache = new FileInfo(
                Path.Combine(
                    CacheFolder.FullName,
                   this.ConstructorArguments.AssamblyFile.Name + ".zip"
                )
            );


            this.AtValidate +=
                delegate
                {
                    // time to extract the zip file if ready and emit the local token

                    if (Cache.Exists)
                    {
                        // great. now compare the times

                        if (this.ConstructorArguments.AssamblyFile.LastWriteTime > Cache.LastWriteTime)
                        {
                            // no dice. the target is newer than our cache.

                            Cache.Delete();
                            Cache.Refresh();
                        }
                    }

                    if (Cache.Exists)
                    {
                        //Debugger.Launch();

                        var zip = Cache.ToZIPFile();

                        foreach (var item in zip.Entries)
                        {
                            var FilePath = Path.Combine(
                                this.ConstructorArguments.TargetDirectory.FullName,
                                item.FileName
                            );

                            this.Add(
                                FilePath,
                                item.Text
                            );

                        }

                        this.WriteLocalTokens();
                        this.WriteLocalFiles();
                    }
                    else
                    {
                        if (this.SourceVersion.Exists)
                            this.SourceVersion.Delete();

                        CacheFolder.Create();
                        CacheFolder.Clear();
                    }
                };

            this.AtWriteTokens +=
                delegate
                {
                    // if the cache still exists it's time to write the zip file

                    //Console.WriteLine("CachedFileGenerator AtWriteTokens" + new { Cache.Exists });

                    if (Cache.Exists)
                        return;

                    CacheFolder.Create();
//.........这里部分代码省略.........
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:101,代码来源:CachedFileGenerator.cs

示例8: UnPublishGallery

        public static OperationResults UnPublishGallery(int id)
        {
            lock (GetGallerySyncRoot(id))
            {
                OperationResult<OperationResults, object> ares = null;

                try
                {
                    ares = GalleryRepository.UnPublish(id);
                }
                catch (Exception ex)
                {
                    Logger.WriteError(ex);
                    throw ex;
                }

                if (ares.Result != OperationResults.Success)
                    return ares.Result;

                string livepath = GetGalleryLivePath(id);

                var dir = new DirectoryInfo(livepath);

                if (dir.Exists)
                {
                    dir.Clear();
                    dir.Refresh();

                    try
                    {
                        dir.Delete(true);
                    }
                    catch (Exception)
                    { }
                }

                return ares.Result;
            }
        }
开发者ID:spbuksh,项目名称:CuratedGalleries,代码行数:39,代码来源:GalleryRuntime.Gallery.cs

示例9: GoGalleryLive

        public static OperationResults GoGalleryLive(int id)
        {
            lock (GetGallerySyncRoot(id))
            {
                string livepath = GetGalleryLivePath(id);

                var dir = new DirectoryInfo(livepath);

                if (dir.Exists)
                {
                    dir.Clear();
                    dir.Refresh();
                }

                var gallery = BuildGalleryOutput(id);

                DirectoryInfo src = new DirectoryInfo(gallery.GetDevPath());

                var content = gallery.LoadContent(false);

                ActionHandler<string, bool, bool> handler = content.SystemFilePathes == null || content.SystemFilePathes.Count == 0 ? (ActionHandler<string, bool, bool>)null :
                    delegate(string path, bool isDir)
                    {
                        if (isDir) return true;
                        return content.SystemFilePathes.FirstOrDefault(x => path.EndsWith(x)) == null;
                    };

                src.CopyTo(dir, handler);

                return OperationResults.Success;
            }
        }
开发者ID:spbuksh,项目名称:CuratedGalleries,代码行数:32,代码来源:GalleryRuntime.Gallery.cs


注:本文中的System.IO.DirectoryInfo.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。