當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。