Пример #1
0
        /// <summary>
        ///     Clones a file or a directory tree into a new path.
        ///     All files in the target will be erased.
        /// </summary>
        public static void Clone(string sourcePath, string targetPath)
        {
            if (FilesystemTools.IsDirectory(sourcePath))
            {
                if (FilesystemTools.Exists(targetPath))
                {
                    FilesystemTools.SafeDelete(targetPath, true, true);
                }
                Directory.CreateDirectory(targetPath);

                // Create all of the directories
                foreach (string dirPath in Directory.GetDirectories(sourcePath, "*",
                                                                    SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath));
                }

                //Copy all the files & Replaces any files with the same name
                foreach (string newPath in Directory.GetFiles(sourcePath, "*.*",
                                                              SearchOption.AllDirectories))
                {
                    File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);
                }
            }
            else
            {
                File.Copy(sourcePath, targetPath, true);
            }
        }
Пример #2
0
        public void IsDirectory_should_be_True_for_directories()
        {
            var dir = CreateDir(@"\TestDir");

            var dirIsDir = FilesystemTools.IsDirectory(dir);

            dirIsDir.Should().Be.True();
        }
Пример #3
0
        public void IsDirectory_should_be_False_for_files()
        {
            using (var tmp = new TempFile())
            {
                tmp.Create();

                FilesystemTools.IsDirectory(tmp.Path).Should().Be.False();
            }
        }
Пример #4
0
 public void IsDirectory_should_Throw_when_entry_missing()
 {
     Executing.This(() => FilesystemTools.IsDirectory(Path.Combine(TestRoot, "nothing")))
     .Should().Throw <FileNotFoundException>();
 }