Sometimes, we need to check the folder size. Although, ls can give your results of certain files, but still you need to struggle to get the folder (directory) size. I wrote one small script to get this with Powershell. You may use this recipe if you are writing something where folder size is required to be checked.
Thanks for reading this article!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------------------ | |
# Script : Get_FolderSize.ps1 | |
# Author : Som DT. | |
# Purpose : Script to find the folder size | |
#------------------------------------------------------------------------------------------ | |
#--Function Declaration --# | |
function Get-FolderSize ([string] $FolderName) | |
{ | |
$value = "{0:N2}" -f ((Get-ChildItem -recurse $FolderName | Measure-Object -property length -sum).Sum / 1MB) | |
echo "Directory Name : ${FolderName} : Size : ${value} MB" | |
} | |
#--Calling the function--# | |
Get-FolderSize "C:\Temp" | |
#------------------------------------------------------------------------------------------ |
Thanks for reading this article!
No comments:
Post a Comment