POWERSHELL 47
Delete Lines Guest on 28th March 2019 02:23:43 PM
  1. #########################
  2. ##### Configuration
  3. #########################
  4. $Target_Directory = "C:\Folder\"
  5. $Max_Lines = 2
  6.  
  7. #########################
  8. ##### Main
  9. #########################
  10. Clear-Host
  11. Write-Host "=== Start" -BackgroundColor Black
  12. $Total_Files = 0
  13. $Deleted_Files = 0
  14. $Skipped_Files = 0
  15. Get-ChildItem $Target_Directory -Filter *.* |
  16. Foreach-Object {
  17.     $Total_Files++
  18.     $Current_Lines = 0;
  19.     gc $_.FullName -read 1000 | % { $Current_Lines += $_.Length };
  20.     if ($Current_Lines -gt $Max_Lines) {
  21.         Write-Host "$($_.FullName) has $Current_Lines/$Max_Lines lines: deleting..." -BackgroundColor Red
  22.         $Deleted_Files++
  23.         Remove-Item -Path $_.FullName -Force
  24.     } else {
  25.         Write-Host "$($_.FullName) has $Current_Lines/$Max_Lines lines: skipping..." -BackgroundColor Green
  26.         $Skipped_Files++
  27.     }
  28. }
  29. Write-Host "===== Results" -BackgroundColor Black
  30. Write-Host "Total Files: $Total_Files | Deleted Files: " -NoNewLine -BackgroundColor Black
  31. Write-Host "$Deleted_Files" -ForegroundColor Red -NoNewline -BackgroundColor Black
  32. Write-Host " | Skipped Files: " -NoNewLine -BackgroundColor Black
  33. Write-Host "$Skipped_Files " -ForegroundColor Green -BackgroundColor Black

RSO cPaste е място за публикуване на код или текст за по-лесно отстраняване на грешки.

Влез или се Регистрай за да редактираш, изтриваш или преглеждаш хронология на твоето публикувано съдържание

Необработен текст

Влез или се Регистрирай за да редактираш или задържиш това съдържание.