Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ls -Recurse -ErrorAction SilentlyContinue | sort -Property Size | select -First 10
- void Main()
- {
- GetFilesSize(@"C:").OrderByDescending(x => x).Take(10).ToList();
- }
- public IEnumerable<long> GetFilesSize(string directory)
- {
- var accessDenied = false;
- var dirList = new string[0];
- try
- {
- dirList = Directory.GetDirectories(directory);
- }
- catch{
- accessDenied = true;
- }
- if(accessDenied) yield break;
- foreach (var dir in dirList)
- {
- foreach (var size in GetFilesSize(dir))
- {
- yield return size;
- }
- }
- foreach (var fileName in Directory.GetFiles(directory))
- {
- if(fileName.Length>=260) continue;
- yield return new FileInfo(fileName).Length;
- }
- }
- PS C:Windowssystem32> $x=Get-ChildItem ./
- PS C:Windowssystem32> $x.GetType()
- IsPublic IsSerial Name BaseType
- -------- -------- ---- --------
- True True Object[] System.Array
- PS C:Windowssystem32> $x[1].GetType()
- IsPublic IsSerial Name BaseType
- -------- -------- ---- --------
- True True DirectoryInfo System.IO.FileSystemInfo
- PS C:Windowssystem32>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement