تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] البحث عن كلمة داخل اكثر من ملف
#2
PHP كود :
string dirScanner = @"\\mypath\";

if (string.IsNullOrWhiteSpace(txtSerialSearch.Text) || string.IsNullOrWhiteSpace(txtSID.Text))
    return;

string[] allFiles = Directory.GetFiles(dirScanner, "
*.txt");

foreach (string file in allFiles)
{
    string[] lines = File.ReadAllLines(file);
    string firstOccurrence = lines.FirstOrDefault(l => l.Contains(txtSerialSearch.Text));
    if (firstOccurrence != null)
    {
        lblOutput.Text = firstOccurrence;
        break;
    }

أو قم بتجربة الاتي :

PHP كود :
   var words = new HashSet<string>(File.ReadAllLines(@"H:\\backstage\my work\uniqword.txt"));          // list of words
 
   var filewords Directory.GetFiles(@"H:\\backstage\my work\categories file text\categories""*.txt"   
        
.Select(=> File.ReadAllText(f))                                                               // read all text in each file
 
       .SelectMany(=> words.Intersect(Regex.Split(s, @"\W|_")))                                      // intersect the set of words in each file with the master list of words, then flatten the list
 
       .GroupBy(=> s).ToDictionary(=> w.Key=> w.Count()); 

الرد }}}
تم الشكر بواسطة: Anas Mahmoud , محمد كريّم , asemshahen5


الردود في هذا الموضوع
RE: البحث عن كلمة داخل اكثر من ملف - بواسطة Rabeea Qbaha - 03-08-20, 02:35 AM


التنقل السريع :


يقوم بقرائة الموضوع: