Advertisement
xPucTu4

Untitled

Jan 15th, 2025
28
0
29 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1.  
  2. await searchRecursively(@"c:\Users\xPucTu4\Downloads\", new Regex(@"^.*\.mp3", RegexOptions.IgnoreCase));
  3.  
  4.  
  5.  
  6. async Task searchRecursively(string rootPath, Regex searchRegex)
  7. {
  8.     await Task.CompletedTask;
  9.     if (this.QueryCancelToken.IsCancellationRequested)
  10.         return;
  11.  
  12.     DirectoryInfo di = new(rootPath);
  13.     foreach (var subDir in di.GetDirectories())
  14.     {
  15.         try
  16.         {
  17.             await searchRecursively(subDir.FullName, searchRegex);
  18.         }
  19.         catch { }
  20.     }
  21.  
  22.     var matches = di.GetFiles()
  23.                     .Where(f => searchRegex.IsMatch(f.Name));
  24.     if (matches.Any())
  25.         matches
  26.         .OrderByDescending(m => m.CreationTime)
  27.         .Select(f => new { f.FullName, f.CreationTime, f.Length, Open = createOpenFolderButton(f.FullName) }).Dump();
  28. }
  29.  
  30. Button createOpenFolderButton(string fileName)
  31. {
  32.     Button buttonOpenDir = new Button("Open");
  33.     buttonOpenDir.Click += (s, a) =>
  34.     {
  35.         Process.Start("explorer.exe", $"/select,\"{fileName}\"");
  36.     };
  37.  
  38.     return buttonOpenDir;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement