diff options
| author | Michael <[email protected]> | 2017-04-21 19:42:41 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-21 19:42:41 -0400 |
| commit | f9f834b1c31f2b6c611f44b2eba8d7ec816145f5 (patch) | |
| tree | 6d4084dfd38ebf11e68647f2a88d3d94e4d76157 /ShiftOS.Objects/ShiftFS.cs | |
| parent | 1e74f09670a89d8fdf51215aa7a275c335e80211 (diff) | |
| download | shiftos_thereturn-f9f834b1c31f2b6c611f44b2eba8d7ec816145f5.tar.gz shiftos_thereturn-f9f834b1c31f2b6c611f44b2eba8d7ec816145f5.tar.bz2 shiftos_thereturn-f9f834b1c31f2b6c611f44b2eba8d7ec816145f5.zip | |
Add copying/moving of files/dirs
Diffstat (limited to 'ShiftOS.Objects/ShiftFS.cs')
| -rw-r--r-- | ShiftOS.Objects/ShiftFS.cs | 57 |
1 files changed, 57 insertions, 0 deletions
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(); } + /// <summary> + /// Copies a file or directory from one path to another, deleting the original. + /// </summary> + /// <param name="path">THe input path, must be a valid directory or file.</param> + /// <param name="target">The output path.</param> + 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); + } + } + + + /// <summary> + /// Copies a file or directory from one path to another. + /// </summary> + /// <param name="path">The input path, must be a valid directory or file.</param> + /// <param name="target">The output path.</param> + 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('/'); |
