private object dir(Dirctx ctx, DirectoryInfo directoryInfo, bool listFiles) { return(ProcessPrepare(new FileOrDirectoryInfo(directoryInfo), null, delegate { FileSystemInfo[] contents = directoryInfo.GetFileSystemInfos(); Array.Sort(contents, comparison); object r = null; List <DirectoryInfo> rec = new List <DirectoryInfo>(); // Display foreach (FileSystemInfo fs in contents) { DirectoryInfo di = (fs as DirectoryInfo); if (di != null) { r = listEntry(ctx, di); if (Recursive && CheckHidden(di)) { rec.Add(di); } if (r != null) { return r; } continue; } FileInfo fi = (fs as FileInfo); if (fi == null || !listFiles) { continue; } r = listEntry(ctx, fi); if (r != null) { return r; } } foreach (DirectoryInfo di in rec) { DirectoryInfo di1 = di; object ret = dir(ctx, di1, true); if (ret != null) { return ret; } } return null; })); }
private object listEntry(Dirctx ctx, FileSystemInfo fsi) { if (!CheckHidden(fsi)) { return(null); } if (fsi is FileInfo) { if (!Files) { return(null); } if (ctx.DirFilter != null && !ctx.DirFilter.IsMatch(fsi.FullName)) { VerboseMessage("{0} did not pass directory filter", fsi.FullName); return(null); } if (ctx.NameFilter != null && !ctx.NameFilter.IsMatch(fsi.FullName)) { return(null); } } if (fsi is DirectoryInfo) { if (!Directories) { return(null); } if (ctx.DirFilter != null && !ctx.DirFilter.IsMatch(fsi.FullName)) { return(null); } } ctx.Entries++; object r = ProcessComplete(new FileOrDirectoryInfo(fsi), null, false, delegate(bool s) { return(null); }); return(r); }
/// Execute action public override object Execute() { string path = Context.TransformStr(From, Transform); object ret = null; Dirctx ctx = new Dirctx { DirFilter = new FullPathFilter(Syntax, Context.TransformStr(DirectoryFilter, Transform), BackslashOption.Add), NameFilter = new FileNameOnlyFilter(Syntax, Context.TransformStr(Filter, Transform)), Entries = 0 }; if (File.Exists(path)) { ret = listEntry(ctx, new FileInfo(path)); } else { DirectoryInfo directory = new DirectoryInfo(path); if (directory.Exists) { bool files = (ctx.DirFilter == null || ctx.DirFilter.IsMatch(directory.FullName)); ret = dir(ctx, directory, files); } } if (ctx.Entries == 0) { if (NoMatch != null) { ret = Context.Execute(NoMatch); } } if (ReturnValue.IsBreak(ret)) { return(null); } ReturnValue.RethrowIfException(ret); return(ret); }
private object listEntry(Dirctx ctx, FileSystemInfo fsi) { if (!CheckHidden(fsi)) return null; if (fsi is FileInfo) { if (!Files) return null; if (ctx.NameFilter != null && !ctx.NameFilter.IsMatch(fsi.FullName)) { return null; } } if (fsi is DirectoryInfo) { if (!Directories) return null; if (ctx.DirFilter != null && !ctx.DirFilter.IsMatch(fsi.FullName)) { return null; } } ctx.Entries++; object r = ProcessComplete(new FileOrDirectoryInfo(fsi), null, false, delegate(bool s) {return null; }); return r; }
private object dir(Dirctx ctx, DirectoryInfo directoryInfo, bool listFiles) { return ProcessPrepare(new FileOrDirectoryInfo(directoryInfo), null, delegate { FileSystemInfo[] contents = directoryInfo.GetFileSystemInfos(); Array.Sort(contents, comparison); object r = null; List<DirectoryInfo> rec = new List<DirectoryInfo>(); // Display foreach (FileSystemInfo fs in contents) { DirectoryInfo di = (fs as DirectoryInfo); if (di != null) { r = listEntry(ctx, di); if (Recursive && CheckHidden(di)) rec.Add(di); if (r != null) return r; continue; } FileInfo fi = (fs as FileInfo); if (fi == null || !listFiles) continue; r = listEntry(ctx, fi); if (r != null) return r; } foreach (DirectoryInfo di in rec) { DirectoryInfo di1 = di; object ret = dir(ctx, di1, true); if (ret != null) return ret; } return null; }); }
/// Execute action public override object Execute() { string path = Context.TransformStr(From, Transform); object ret = null; Dirctx ctx = new Dirctx { DirFilter = new FullPathFilter(Syntax, Context.TransformStr(DirectoryFilter, Transform), BackslashOption.Add), NameFilter = new FileNameOnlyFilter(Syntax, Context.TransformStr(Filter, Transform)), Entries = 0 }; if (File.Exists(path)) ret = listEntry(ctx, new FileInfo(path)); else { DirectoryInfo directory = new DirectoryInfo(path); if (directory.Exists) { bool files = (ctx.DirFilter == null || ctx.DirFilter.IsMatch(directory.FullName)); ret = dir(ctx, directory,files); } } if (ctx.Entries==0) { if (NoMatch != null) ret=Context.Execute(NoMatch); } if (ReturnValue.IsBreak(ret)) return null; ReturnValue.RethrowIfException(ret); return ret; }