private static string[] DirList(string sDir, string fnd) { try { List <string> itms = new List <string>(0); itms.AddRange(from d in Filesystem.GetDirectories(sDir) where d.StartsWith(fnd) select d.Remove(0, sDir.Length) + "\\"); itms.AddRange(from f in Filesystem.GetFiles(sDir) where f.StartsWith(fnd) select f.Remove(0, sDir.Length)); return(itms.ToArray()); } catch { } return(null); }
private static string[] DirList2(string sDir) { try { List <string> itms = new List <string>(0); itms.AddRange(Filesystem.GetDirectories(sDir).Select(d => d + "\\")); itms.AddRange(Filesystem.GetFiles(sDir)); return(itms.ToArray()); } catch { } return(null); }
private static void DirSearch(string sDir, string fnd, List <string> itms) { try { Regex tmp = new Regex(fnd.Replace(@"\\", @"\\\\").Replace(@".", @"\.").Replace(@"*", @".*").Replace(@"?", @".?").Replace(@"[", @"\[").Replace(@"]", @"\]".Replace(@"(", @"\(").Replace(@")", @"\)")), RegexOptions.IgnoreCase); itms.AddRange(Filesystem.GetFiles(sDir).Where(f => tmp.IsMatch(f.Substring(f.LastIndexOf("\\") + 1)))); foreach (string d in Filesystem.GetDirectories(sDir)) { DirSearch(d, fnd, itms); } } catch { } }
private static void GetApps(string sDir, List <string> itms) { try { Regex tmp = new Regex(@".*\.lnk", RegexOptions.IgnoreCase); itms.AddRange(Filesystem.GetFiles(sDir).Where(f => tmp.IsMatch(f.Substring(f.LastIndexOf("\\") + 1)))); foreach (string d in Filesystem.GetDirectories(sDir)) { itms.Add(d + "\\"); GetApps(d, itms); } } catch { } }