최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday

티스토리 뷰

 

윈도우 폴더안의 폴더명, 파일개수, 파일처음 ~ 파일끝, 파일용량 표시

 

function Convert-Unit {
    param([float] $size = 0)

    if ($size -gt  1073741824) {
        $ConvertSize = [math]::Round($size/1GB, 2).toString() + ' GB';
    } elseif ($size -gt 1048576) {
        $ConvertSize = [math]::Round($size/1MB, 2).toString() + ' MB';
    } elseif ($size -gt 1024) {
        $ConvertSize = [math]::Round($size/1KB, 2).toString() + ' KB';
    } else {
        $ConvertSize = $size.toString() + 'Bytes';
    }
    return $ConvertSize
}

function Get-FolderSize {
    param([system.IO.DirectoryInfo] $objPath)
    return (Convert-Unit (Get-ChildItem -Path $objPath -Recurse | Measure-Object -Property length -Sum).Sum);
}

#Get-ChildItem $strPath -Directory | % {'    ' + $_.FullName + ' : ' + (Get-FolderSize $_.FullName);}

$searchPath = ".\"
$seperate = " | "
$a=@{}
Get-ChildItem $searchPath -Recurse -Directory -ErrorAction Ignore | 
Foreach { 
	$a[$_.FullName] = 
	
		# 음식명
		($_.Fullname).Split('\\')[ ($_.Fullname).Split('\\').length-1 ] + $seperate +
		
		# 수량
		(Get-ChildItem -path $_.Fullname -recurse -ErrorAction Ignore).Count + " 개" + $seperate +
		
		# 시작파일 ~ 끝파일
		((Get-ChildItem -path $_.Fullname | Select-Object -First 1).Basename).split('_')[1] + " ~ " +
		((Get-ChildItem -path $_.Fullname | Select-Object -Last 1).Basename).split('_')[1] + $seperate +
		
		# 용량표시
		(Convert-Unit (Get-ChildItem -Path $_.Fullname -Recurse | Measure-Object -Property length -Sum).Sum) + " "+
		
		((Get-ChildItem -path $_.Fullname -recurse | Measure-Object -property length -ErrorAction Ignore -sum).sum /1GB).toString() + " GB"
}
#$a.GetEnumerator() | Format-List | Out-File report.txt
#$a.GetEnumerator() | Sort Value -Descending | Format-List | Out-File report.txt
$a.GetEnumerator() | Format-Table -AutoSize | Out-File report.txt
#$a.GetEnumerator() | Format-Table -AutoSize

 

댓글