Forum Discussion

ankit shukla's avatar
ankit shukla
Iron Contributor
May 25, 2020

Check file size and take desired action

I have location where a software saves an Excel File for me. ( I control the location, time and other things)

 

I have a powershell script already that emails this file to my Outlook Groups.

 

I need to see if i can add another code before emailing which compares/analysis the size of the file , lets say the file is 500 BYtes ( no data in the file) , then do not email or the next code doesn't execute/
if it is more than 500 bytes, then yes, execute the next line of code.

2 Replies

  • gastone's avatar
    gastone
    Brass Contributor

    ankit shukla 

    something like this

     

     

    if ((dir c:\temp\yourExcelfile.xlsx ).Length -gt 500) {"do hard work to sen the e-mail"}
    #or
    (dir *.xlsx -file)|
         ?{ $_.Length -gt 500}|
             %{"Is greater do hard work to send the e-mail with file $($_.fullname)"}

     

     

  • Manfred101's avatar
    Manfred101
    Iron Contributor

    ankit shukla You can do something like this: 

    Get-ChildItem | where { (-NOT $_.PSIsContainer) -and ($_.Length -gt 0.5KB) }

    Good luck

     

    Grtz, Manfred de Laat 

Resources