Monday, October 12, 2009

Powershell | Determine file size

$myfile = "c:\test.zip"
$minsize = "100" # minimum file size is set to 100kb

if(Test-Path $myfile) # if my file exists
{

$myfilesize=Get-ChildItem $myfile | Select-Object @{Name="Kbytes";Expression={$_.Length / 1Kb}}

#clean unnecessary data
$myfilesize=[regex]::replace($myfilesize, "@{Kbytes=", "")
$myfilesize=[regex]::replace($myfilesize, ".[\d]*}", "")

if($myfilesize -ge $minsize)
{
#TODO: file is greater or equal than 100kb, do something
}

}

No comments:

Post a Comment