
Kod: Tümünü seç
# FolderLister v4 - Recursive with colored subfolders, summary and total size
function List-Folder {
param(
[string]$Path,
[int]$Indent = 0
)
$indentStr = " " * ($Indent * 4) # 4 spaces per indent
# Ana klasör başlığı
if ($Indent -eq 0) {
Write-Host ("+ " + "=" * 50)
Write-Host ("Folder: $Path") -ForegroundColor DarkMagenta
Write-Host ("+ " + "=" * 50)
} else {
# Alt klasör başlığı
Write-Host ("$$$ Subfolder: $Path $$$") -ForegroundColor Red
Write-Host (" " * $Indent + "+ " + "=" * 50)
Write-Host (" " * $Indent + "Folder: $Path") -ForegroundColor DarkMagenta
Write-Host (" " * $Indent + "+ " + "=" * 50)
}
$files = Get-ChildItem -LiteralPath $Path -File
foreach ($file in $files) {
$sizeMB = [math]::Round($file.Length / 1MB, 2)
Write-Host ($indentStr + "[FILE] $($file.Name)")
Write-Host ($indentStr + " Path : $($file.FullName)")
Write-Host ($indentStr + " Size : $sizeMB MB")
Write-Host ($indentStr + " Created : $($file.CreationTime)")
Write-Host ($indentStr + " LastModified: $($file.LastWriteTime)")
# Toplam boyutu ekle
$script:TotalSizeBytes += $file.Length
}
$subfolders = Get-ChildItem -LiteralPath $Path -Directory
foreach ($sub in $subfolders) {
List-Folder -Path $sub.FullName -Indent ($Indent + 1)
}
# Update global counters
$script:TotalFolders += $subfolders.Count
$script:TotalFiles += $files.Count
}
# Başlangıç
$folder = Read-Host "Please enter the folder path"
if (-Not (Test-Path $folder)) {
Write-Host "Folder not found!" -ForegroundColor Red
exit
}
# Initialize counters
$script:TotalFolders = 0
$script:TotalFiles = 0
$script:TotalSizeBytes = 0
Write-Host "`nListing files recursively from folder: $folder" -ForegroundColor Cyan
List-Folder -Path $folder
# Toplam boyutu formatla
if ($script:TotalSizeBytes -gt 1GB) {
$totalSize = [math]::Round($script:TotalSizeBytes / 1GB, 2)
$sizeUnit = "GB"
} else {
$totalSize = [math]::Round($script:TotalSizeBytes / 1MB, 2)
$sizeUnit = "MB"
}
Write-Host "`nListing completed." -ForegroundColor Green
Write-Host ("Summary:") -ForegroundColor Yellow
Write-Host ("Total main folder : 1")
Write-Host ("Total subfolders : $script:TotalFolders")
Write-Host ("Total files : $script:TotalFiles")
Write-Host ("Total size : $totalSize $sizeUnit")
Read-Host "Press Enter to exit..."
Rekürsif kelimesi ne anlama geliyor.?
CEVAP :
Rekürsif, bir işlemin ya da fonksiyonun kendisini daha küçük bir alt problem için tekrar çağırmasıdır. Bir şey “rekürsif” olduğunda, aynı mantık daha derin seviyelerde aynı şekilde uygulanır. Örneğin, bir klasörün içindeki alt klasörleri taramak için kullanılan fonksiyon, her alt klasöre geldiğinde aynı fonksiyonu o klasör için tekrar çalıştırır; bu, klasör ağacının tüm dallarına ulaşana kadar devam eder.
Kodladığım bu .PS1 betiği hakkında şunu özetleyerek yazabilirim....
1. dosya ve klasör incelemesi konusundaki pratik bir araç arayan kullanıcılar için...(aynen benim gibi)
2.@BlueLife Dosya Listesi v1.0 yazılımından ilham alındı.
3.Görsel ayrım (renkli başlıklar, girintili çıktı) sayesinde uzun listeler bile okunabilir.
4.Özet raporu (toplam klasör, dosya ve boyut) doğrudan ihtiyacı karşılar; özellikle depolama yönetimi ve raporlama konularında ilgi çeker.
5.Basit kullanım (tek bir yol sorusu, otomatik tarama) yeni başlayanlar ve sistem yöneticileri için düşük öğrenme eğrisi ...
Güle güle kullanın.Paylaşımlarım devam edecek....

