From f9f834b1c31f2b6c611f44b2eba8d7ec816145f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 21 Apr 2017 19:42:41 -0400 Subject: Add copying/moving of files/dirs --- ShiftOS.Objects/ShiftFS.cs | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'ShiftOS.Objects') diff --git a/ShiftOS.Objects/ShiftFS.cs b/ShiftOS.Objects/ShiftFS.cs index d35e5b7..713bd17 100644 --- a/ShiftOS.Objects/ShiftFS.cs +++ b/ShiftOS.Objects/ShiftFS.cs @@ -401,6 +401,63 @@ namespace ShiftOS.Objects.ShiftFS return paths.ToArray(); } + /// + /// Copies a file or directory from one path to another, deleting the original. + /// + /// THe input path, must be a valid directory or file. + /// The output path. + public static void Move(string path, string target) + { + if (FileExists(path)) + { + WriteAllBytes(target, ReadAllBytes(path)); + Delete(path); + } + else if (DirectoryExists(path)) + { + if (!DirectoryExists(target)) + CreateDirectory(target); + foreach (var file in GetFiles(path)) + { + var name = GetFileInfo(file).Name; + Copy(file, target + "/" + name); + } + foreach (var dir in GetDirectories(path)) + { + string name = GetDirectoryInfo(dir).Name; + Copy(dir, target + "/" + name); + } + Delete(path); + } + } + + + /// + /// Copies a file or directory from one path to another. + /// + /// The input path, must be a valid directory or file. + /// The output path. + public static void Copy(string path, string target) + { + if (FileExists(path)) + WriteAllBytes(target, ReadAllBytes(path)); + else if (DirectoryExists(path)) + { + if (!DirectoryExists(target)) + CreateDirectory(target); + foreach(var file in GetFiles(path)) + { + var name = GetFileInfo(file).Name; + Copy(file, target + "/" + name); + } + foreach(var dir in GetDirectories(path)) + { + string name = GetDirectoryInfo(dir).Name; + Copy(dir, target + "/" + name); + } + } + } + public static string[] GetFiles(string path) { string[] pathlist = path.Split('/'); -- cgit v1.2.3