private CameraFile loadFolders(string cwd, List <string> output, List <string> allFiles) { CameraFile folder = new CameraFile(port); folder.path = cwd; folder.isFolder = true; foreach (string d in getDirectoriesInDirectory(cwd, output)) { folder.children.Add(loadFolders(d, getDirectoriesInDirectory(d, output), allFiles)); } List <string> files = getFilesInDirectory(cwd, allFiles); foreach (string file in files) { CameraFile f = new CameraFile(port); f.path = file; f.isFolder = false; folder.children.Add(f); } return(folder); }
/// <summary> /// Delete all files in the given folder /// </summary> /// <param name="camera">On which camera should we do this</param> /// <param name="path">Object of the folder to clear</param> public static void EmptyFolder(Camera camera, CameraFile path) { if (path.isFolder) { Utilities.gphoto2($"--port={camera.port} --delete-all-files --folder {path.path}"); } else { throw new Exception("Trying to empty a folder but path given contains a file!"); } }
/// <summary> /// Internal function to see if the file exists without asking the camera (Is part of Exists() which does check the camera) /// </summary> /// <param name="node"></param> /// <param name="path"></param> /// <returns></returns> private static bool exists(CameraFile node, string path) { if (node == null) { return(false); } if (node.path == path) { return(true); } foreach (CameraFile child in node.children) { var found = Find(child, path); if (found != null) { return(true); } } return(false); }
/// <summary> /// Get the file object from a path /// </summary> /// <param name="node">The root folder (or any subfolder you want to search in)</param> /// <param name="path">The path to the file you are trying to retrieve</param> /// <returns></returns> public static CameraFile Find(CameraFile node, string path) { if (node == null) { return(null); } if (node.path == path) { return(node); } foreach (CameraFile child in node.children) { var found = Find(child, path); if (found != null) { return(found); } } return(null); }
/// <summary> /// Get all file objects of files in a specified folder /// </summary> /// <param name="node">The root folder (or any subfolder you want to search in)</param> /// <param name="path">The path of the folder relative to the node</param> /// <returns></returns> public static List <CameraFile> FindAll(CameraFile node, string path) { if (node == null) { return(null); } if (node.path == path && node.isFolder) { return(node.children); } foreach (CameraFile child in node.children) { var found = Find(child, path); if (found != null && found.isFolder) { return(found.children); } } return(null); }