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


C# DirectoryInfo.SafeDelete方法代码示例

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


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

示例1: SafeDelete

 public void SafeDelete()
 {
     var dir = new DirectoryInfo("abc");
     dir.SafeDelete(true);
     dir.Refresh();
     Assert.That(dir.SafeDelete(true), Is.False);
     Directory.CreateDirectory(dir.GetDirectory("test2").FullName);
     dir.Refresh();
     Assert.That(dir.SafeDelete(true), Is.True);
     dir.Refresh();
     Assert.That(dir.Exists, Is.False);
 }
开发者ID:exKAZUu,项目名称:Paraiba,代码行数:12,代码来源:DirectoryInfoExtensionsTest.cs

示例2: 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

示例3: CopyToDirectory

        public static void CopyToDirectory(this DirectoryInfo source, DirectoryInfo destination, bool deleteDestination)
        {
            if (deleteDestination)
            {
                if (destination.Exists)
                    destination.SafeDelete();
            }

            if (!destination.Exists)
                destination.Create();

            LogCopyTask(source, destination);

            CopyFiles(source, destination);

            CopyDirectories(source, destination, deleteDestination);
        }
开发者ID:emmekappa,项目名称:horn_src,代码行数:17,代码来源:FileSystemInfoExtensions.cs

示例4: clone_git_repo_and_append_to_existing_solution

        public void clone_git_repo_and_append_to_existing_solution()
        {
            var tmpDir = FileSystem.Combine("Templating", Guid.NewGuid().ToString());
            var repoZip = FileSystem.Combine("Templating", "repo.zip");
            _zipService.ExtractTo(repoZip, tmpDir, ExplodeOptions.DeleteDestination);

            var solutionFile = FileSystem.Combine("Templating", "sample", "myproject.txt");
            var oldContents = _fileSystem.ReadStringFromFile(solutionFile);
            var solutionDir = _fileSystem.GetDirectory(solutionFile);

            _commandInput.GitFlag = "file:///{0}".ToFormat(_fileSystem.GetFullPath(tmpDir).Replace("\\", "/"));
            _commandInput.ProjectName = "MyProject";
            _commandInput.SolutionFlag = solutionFile;
            _commandInput.OutputFlag = solutionDir;
            _commandInput.RakeFlag = "init.rb";

            _command
                .Execute(_commandInput)
                .ShouldBeTrue();

            _fileSystem
                .DirectoryExists("Templating", "sample", "MyProject")
                .ShouldBeTrue();

            _fileSystem
                .DirectoryExists("Templating", "sample", "MyProject.Tests")
                .ShouldBeTrue();

            _fileSystem
                .FileExists("Templating", "sample", "MyProject", "MyProject.csproj")
                .ShouldBeTrue();

            _fileSystem
                .FileExists("Templating", "sample", "MyProject.Tests", "MyProject.Tests.csproj")
                .ShouldBeTrue();

            // .fubuignore
            _fileSystem
                .FileExists("Templating", "sample", MoveContent.FubuIgnoreFile)
                .ShouldBeFalse();

            _fileSystem
                .FileExists("Templating", "sample", "ignored.txt")
                .ShouldBeFalse();

            _fileSystem
                .FileExists("Templating", "sample", "MyProject.xml")
                .ShouldBeTrue();

            var solutionContents = _fileSystem.ReadStringFromFile(solutionFile);

            // cleanup first
            var info = new DirectoryInfo(tmpDir);
            info.SafeDelete();
            _fileSystem.DeleteDirectory("Templating", "sample", "MyProject");
            _fileSystem.DeleteDirectory("Templating", "sample", "MyProject.Tests");
            _fileSystem.WriteStringToFile(solutionFile, oldContents);

            var lines = ((SolutionFileService) _command.SolutionFileService).SplitSolution(solutionContents);
            var guid = _command.KeywordReplacer.Replace("GUID1");
            lines[2].ShouldEqual("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"MyProject\", \"MyProject\\MyProject.csproj\", \"{" + guid +  "}\"");
            lines[3].ShouldEqual("EndProject");
        }
开发者ID:mmoore99,项目名称:fubumvc,代码行数:63,代码来源:NewCommandEndToEndTester.cs

示例5: Execute

        public void Execute(TemplatePlanContext context)
        {
            var fileSet = new FileSet
                                   {
                                       DeepSearch = false,
                                       Include = "*.*",
                                       Exclude = "*.exe;*.dll;.git;*{0};".ToFormat(FubuIgnoreFile)
                                   };
            var fubuIgnore = FileSystem.Combine(context.TempDir, FubuIgnoreFile);
            if(_fileSystem.FileExists(fubuIgnore))
            {
                _fileSystem
                    .ReadStringFromFile(fubuIgnore)
                    .SplitOnNewLine()
                    .Each(ignore =>
                              {
                                  fileSet.Exclude += "{0};".ToFormat(ignore);
                              });
            }

            var excludedFiles = fileSet.ExcludedFilesFor(context.TempDir);
            _fileSystem
                .FindFiles(context.TempDir, fileSet)
                .Where(file => !excludedFiles.Contains(file))
                .Each(from =>
                          {
                              var destination = Path.Combine(context.TargetPath, _fileSystem.GetFileName(from));
                              if (_fileSystem.FileExists(destination)) _fileSystem.DeleteFile(destination);
                              _fileSystem.MoveFile(from, destination);
                          });

            _fileSystem
                .ChildDirectoriesFor(context.TempDir)
                .Each(directory =>
                          {
                              var destinationName = _fileSystem.GetFileName(directory);
                              if(destinationName == ".git")
                              {
                                  return;
                              }

                              var destination = Path.Combine(context.TargetPath, destinationName);
                              if (_fileSystem.DirectoryExists(destination))
                              {
                                  _fileSystem.DeleteDirectory(destination);
                              }
                              _fileSystem.MoveDirectory(directory, destination);
                          });

            var info = new DirectoryInfo(context.TempDir);
            info.SafeDelete();
        }
开发者ID:mmoore99,项目名称:fubumvc,代码行数:52,代码来源:MoveContent.cs


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