private static void CallCallback(DeletePathDelegate callback, string path, bool isFile, bool success) { if (callback != null) { callback(path, isFile, success, success ? "" : GetLastErrorString()); } }
public static void DeletePath(string path, bool force, DeletePathDelegate callback) { if (File.Exists(path)) { bool success = File.Delete(path, force); CallCallback(callback, path, true, success); } else { DeletePathRecurse(path, force, callback); CallCallback(callback, path, false, Directory.Remove(path, force)); } }
private static void DeletePathRecurse(string directory, bool force, DeletePathDelegate callback) { foreach (string file in Directory.GetFiles(directory)) { CallCallback(callback, file, true, File.Delete(file, force)); } foreach (string subdir in Directory.GetDirectories(directory)) { System.IO.Directory.Delete(subdir, true); CallCallback(callback, subdir, false, true); } }
private static void DeletePathRecurse( string directory, bool force, DeletePathDelegate callback ) { foreach ( string file in Directory.GetFiles( directory ) ) { CallCallback( callback, file, true, File.Delete( file, force ) ); } foreach ( string subdir in Directory.GetDirectories( directory ) ) { System.IO.Directory.Delete( subdir, true ); CallCallback( callback, subdir, false, true ); } }
private static void CallCallback( DeletePathDelegate callback, string path, bool isFile, bool success ) { if ( callback != null ) callback( path, isFile, success, success ? "" : GetLastErrorString() ); }
public static void DeletePath( string path, bool force, DeletePathDelegate callback ) { if ( File.Exists( path ) ) { bool success = File.Delete( path, force ); CallCallback( callback, path, true, success ); } else { DeletePathRecurse( path, force, callback ); CallCallback( callback, path, false, Directory.Remove( path, force ) ); } }