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 FileDescriptor[] GetFileDescriptors(string path, string pattern = null, bool recursive = false) { string realPath = PathExpress.ResolvePath(path); ICollection <FileDescriptor> results = new List <FileDescriptor>(); string[] filePaths = pattern == null?Directory.GetFiles(realPath) : Directory.GetFiles(realPath, pattern); foreach (string filePath in filePaths) { FileDescriptor fileDescriptor = FileExpress.GetFileDescriptor(filePath); results.Add(fileDescriptor); } if (recursive) { string[] directoryPaths = Directory.GetDirectories(realPath); foreach (string directoryPath in directoryPaths) { FileDescriptor[] fileDescriptors = GetFileDescriptors(directoryPath, pattern, true); foreach (FileDescriptor fileDescriptor in fileDescriptors) { results.Add(fileDescriptor); } } } return(results.ToArray()); }