private void Delete(string directory, GLib.IFile dir, bool recursive) { if (!dir.Exists) { return; } if (dir.QueryFileType (FileQueryInfoFlags.NofollowSymlinks, null) != FileType.Directory) { return; } // If native, use the System.IO recursive delete if (dir.IsNative && !DisableNativeOptimizations) { System.IO.Directory.Delete (directory, recursive); return; } if (recursive) { foreach (string child in GetFiles (dir, false)) { FileFactory.NewForUri (child).Delete (); } foreach (string child in GetDirectories (dir, false)) { Delete (child, GetDir (child, true), true); } } dir.Delete (); }
private void DeleteEmptyDirectory(GLib.File directory) { // if the directory we're dealing with is not in the // F-Spot photos directory, don't delete anything, // even if it is empty string photo_uri = SafeUri.UriToFilename (Global.PhotoUri.ToString ()); bool path_matched = directory.Path.IndexOf (photo_uri) > -1; if (directory.Path.Equals (photo_uri) || !path_matched) return; if (DirectoryIsEmpty (directory)) { try { Log.DebugFormat ("Removing empty directory: {0}", directory.Path); directory.Delete (); } catch (GLib.GException e) { // silently log the exception, but don't re-throw it // as to not annoy the user Log.Exception (e); } // check to see if the parent is empty DeleteEmptyDirectory (directory.Parent); } }
private void Delete (string directory, GLib.File dir, bool recursive) { if (!dir.Exists) { Console.WriteLine ("{0} doesn't exist", directory); return; } if ((dir.QueryFileType (FileQueryInfoFlags.None, null) & FileType.Directory) == 0) { Console.WriteLine ("{0} isn't directory", directory); return; } // If native, use the System.IO recursive delete if (dir.IsNative && !DisableNativeOptimizations) { System.IO.Directory.Delete (directory, recursive); return; } if (recursive) { foreach (string child in GetFiles (dir, false)) { FileFactory.NewForUri (child).Delete (); } foreach (string child in GetDirectories (dir, false)) { Delete (child, GetDir (child, true), true); } } dir.Delete (); }