Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. ls -Recurse -ErrorAction SilentlyContinue | sort -Property Size | select -First 10
  2.  
  3. void Main()
  4. {
  5. GetFilesSize(@"C:").OrderByDescending(x => x).Take(10).ToList();
  6. }
  7.  
  8. public IEnumerable<long> GetFilesSize(string directory)
  9. {
  10. var accessDenied = false;
  11. var dirList = new string[0];
  12. try
  13. {
  14. dirList = Directory.GetDirectories(directory);
  15. }
  16. catch{
  17. accessDenied = true;
  18. }
  19.  
  20. if(accessDenied) yield break;
  21.  
  22. foreach (var dir in dirList)
  23. {
  24. foreach (var size in GetFilesSize(dir))
  25. {
  26. yield return size;
  27. }
  28. }
  29.  
  30. foreach (var fileName in Directory.GetFiles(directory))
  31. {
  32. if(fileName.Length>=260) continue;
  33. yield return new FileInfo(fileName).Length;
  34. }
  35. }
  36.  
  37. PS C:Windowssystem32> $x=Get-ChildItem ./
  38. PS C:Windowssystem32> $x.GetType()
  39.  
  40. IsPublic IsSerial Name BaseType
  41. -------- -------- ---- --------
  42. True True Object[] System.Array
  43.  
  44. PS C:Windowssystem32> $x[1].GetType()
  45.  
  46. IsPublic IsSerial Name BaseType
  47. -------- -------- ---- --------
  48. True True DirectoryInfo System.IO.FileSystemInfo
  49.  
  50. PS C:Windowssystem32>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement