Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Check single file size

41 views
Skip to first unread message

Cathy

unread,
Nov 15, 2012, 4:44:36 PM11/15/12
to
I am just getting started in powershell, (have been using DOS batch files so
far.)

I would like some assistance to write a simple batch file to check the file
size of a specific file. The file is not allowed to be more than 5gb.

The steps are therefore

1. Set Max_file_size = 5gb
2. Set warning_level = 10%
3. Set Warning_File_size = Max_file_size - (Max_file_size * warning_level)
3. Check file_size
4. if file_size > Warning_file_size
Echo File is too large
endif

If anybody could help me get this scripted I would really appreciate it

regards
C

David Trimboli

unread,
Nov 16, 2012, 11:10:20 AM11/16/12
to
On 11/15/2012 4:44 PM, Cathy wrote:
> I would like some assistance to write a simple batch file to check the
> file size of a specific file. The file is not allowed to be more than 5gb.
>
> The steps are therefore
>
> 1. Set Max_file_size = 5gb
> 2. Set warning_level = 10%
> 3. Set Warning_File_size = Max_file_size - (Max_file_size * warning_level)
> 3. Check file_size
> 4. if file_size > Warning_file_size
> Echo File is too large
> endif
>
> If anybody could help me get this scripted I would really appreciate it

Steps 1–3 always result in a warning file size of 4.5 GB. I've condensed
these steps; I leave it to the reader to expand them if desired.

I have not included any kind of error-checking. It is written as a
script, though you could instead make it a function.


param($File_Path)
$Warning_File_Size = 4.5GB
$File = Get-Item -Path $File_Path
if ($File.Length -gt $Warning_File_Size)
{
Write-Host "File is too large"
}


--
David Trimboli
http://www.trimboli.name/

Cathy

unread,
Nov 17, 2012, 4:24:54 PM11/17/12
to
Thanks for the response. Really appreciate this

> Steps 1–3 always result in a warning file size of 4.5 GB. I've condensed
> these steps; I leave it to the reader to expand them if desired.

I did this to allow me to change the warning percentage to suit.

> I have not included any kind of error-checking. It is written as a script,
> though you could instead make it a function.

I will look into this once I become more comfortable in Powershell

Thanks again for your help

0 new messages