public static void RecursiveSetAttributes(string path, FileAttributeSetArgument attr) { string realPath = PathExpress.ResolvePath(path); string[] dirPaths = Directory.GetDirectories(realPath); string[] filePaths = Directory.GetFiles(realPath); try { SetAttribute(realPath, attr); } catch (Exception ex) { TfxLogger.Error(DefaultLogTag.System, s_instance, "RecursiveSetAttributes", string.Empty, ex); } foreach (string dirPath in dirPaths) { RecursiveSetAttributes(dirPath, attr); } foreach (string filePath in filePaths) { try { FileExpress.SetAttribute(filePath, attr); } catch (Exception ex) { TfxLogger.Error(DefaultLogTag.System, s_instance, "RecursiveSetAttributes", string.Empty, ex); } } }
public static void RecursiveDelete(string path, bool aggressiveMode = false) { string realPath = PathExpress.ResolvePath(path); if (aggressiveMode) { try { Directory.Delete(realPath, true); } catch (Exception ex) { TfxLogger.Error(DefaultLogTag.System, s_instance, "RecursiveDelete", string.Empty, ex); string[] dirPaths = Directory.GetDirectories(realPath); string[] filePaths = Directory.GetFiles(realPath); foreach (string dirPath in dirPaths) { RecursiveDelete(dirPath, true); } foreach (string filePath in filePaths) { try { File.Delete(filePath); } catch (Exception exc) { TfxLogger.Error(DefaultLogTag.System, s_instance, "RecursiveDelete", string.Empty, exc); } } } } else { Directory.Delete(realPath, true); } }