WHERE (chaine LIKE '%cs' OR chaine LIKE '%.res') AND NOT (chaine LIKE '%\.git\\%' OR chaine LIKE '%\.vs\\%')
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionList<string> contient = new List<string> { "test2", "a" }; List<string> neContientPas = new List<string> { "git\\"}; List<string> finitPar = new List<string> { ".cs", ".resx" }; private void button1_Click(object sender, EventArgs e) { string dossierDepart = System.IO.Path.GetDirectoryName(Application.StartupPath); List<string> fichiers = (from f in Directory.GetFiles(dossierDepart) where Recherche(f) select f ).ToList(); } private bool Recherche(string Texte) { //on commence par exclure les "ne contient pas" foreach (string aExclure in neContientPas) if (Texte.Contains(aExclure)) return false; //on teste ensuite que la chaine contient au moins un élément de "contient" bool ok = false; foreach(string aTrouver in contient) if(Texte.Contains(aTrouver)) { ok = true; break;//on sort du foreach } if (!ok) return false; //idem pour les fins de chaines foreach (string fin in finitPar) if (Texte.EndsWith(fin)) return true; return false; }
List<string> contient = new List<string> { "test2", "a" }; List<string> neContientPas = new List<string> { "git\\", ".vs\\" }; List<string> finitPar = new List<string> { ".cs", ".resx" }; private void button1_Click(object sender, EventArgs e) { string dossierDepart = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)); List<string> fichiers = (from f in Directory.GetFiles(dossierDepart) where !neContientPas.Any(x => f.Contains(x)) && contient.Any(x => f.Contains(x)) && finitPar.Any(x => f.EndsWith(x)) select f ).ToList(); }
List<string> contient = new List<string>(); //{ "test2", "a" }; List<string> neContientPas = new List<string> { "git\\", ".vs\\" }; List<string> finitPar = new List<string>(); // { ".cs", ".resx" }; private void button1_Click(object sender, EventArgs e) { string dossierDepart = Path.GetDirectoryName(Path.GetDirectoryName(Application.StartupPath)); List<string> fichiers = (from f in Directory.GetFiles(dossierDepart) where !neContientPas.Any(x => f.Contains(x)) && (contient.Count == 0 || contient.Any(x => f.Contains(x))) && (finitPar.Count == 0 ||finitPar.Any(x => f.EndsWith(x))) select f ).ToList(); }
from f in Directory.GetFiles(dossierDepart,"*",SearchOption.AllDirectories)
Mais je doute que cette fonction accepte les caractères génériques du type * et ? chers à Windows. Cela reviendrait à transformer à la volée le "*" en ".+" et le "?" en "." et utiliser une expression régulière. </bloc> Oui mais c’est ton code qui génèrerait cette regex, pas l’utilisateurC’est sûr
<block>cela risque d'avoir des effets de bord
Ceci dit, je me replonge dans Visual Studio, mon programme n'attend plus que les filtres pour être terminé.On n,a pas traité la casse et les diacritiques, veux ru le faire?
private static bool IsExcluded(string TargetPath, string[] WinPatterns) { foreach (string Excl in WinPatterns) { if (Excl == "") // Pour traiter les chaines vides entrées par erreur par l'utilisateur continue; string Pattern = "^" + Regex.Escape(Excl).Replace(@"\*", ".*").Replace(@"\?", ".") + "$"; if (Regex.IsMatch(TargetPath, Pattern)) return true; } return false; }