Skip to content

Commit d7e55d4

Browse files
committed
PhysicalFileSystem: teach ability to copy a directory
Teach PhysicalFileSystem the ability to copy an entire directory to a destination path.
1 parent ed07bc4 commit d7e55d4

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

GVFS/GVFS.Common/FileSystem/PhysicalFileSystem.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ public virtual void DeleteDirectory(string path, bool recursive = true)
3939
directory.Delete();
4040
}
4141

42+
public virtual void CopyDirectoryRecursive(string srcDirectoryPath, string dstDirectoryPath)
43+
{
44+
DirectoryInfo srcDirectory = new DirectoryInfo(srcDirectoryPath);
45+
46+
if (!this.DirectoryExists(dstDirectoryPath))
47+
{
48+
this.CreateDirectory(dstDirectoryPath);
49+
}
50+
51+
foreach (FileInfo file in srcDirectory.EnumerateFiles())
52+
{
53+
this.CopyFile(file.FullName, Path.Combine(dstDirectoryPath, file.Name), overwrite: true);
54+
}
55+
56+
foreach (DirectoryInfo subDirectory in srcDirectory.EnumerateDirectories())
57+
{
58+
this.CopyDirectoryRecursive(subDirectory.FullName, Path.Combine(dstDirectoryPath, subDirectory.Name));
59+
}
60+
}
61+
4262
public virtual bool FileExists(string path)
4363
{
4464
return File.Exists(path);

0 commit comments

Comments
 (0)