none
Query size of an open file RRS feed

  • Question

  • Hi all. I would like to know how I can query the size of a file that is actively being written to. I've opened the file using:

    $fdFile = New-Object System.IO.StreamWriter(New-Object IO.FileStream($FilePath, $mode, $access, $sharing))

    When writing to the file I'd like the check the size of the file in order to determine if I need to roll the log not. The file will be in an open state when I want to check this.

    Any help would be greatly appreciated.


    -- Tim.

    Monday, October 29, 2018 4:34 PM

Answers

  • After a log file reaches a given size I want to roll the log file. OutLog.log --> OutLog-001.log etc.

    I've found what I needed.

    $fdFile.BaseStream.Length gives me the size on a live ongoing basis. Gotta love Powershell.  :-)


    -- Tim.

    Monday, October 29, 2018 5:55 PM

All replies

  • First, what have you tried, and with what results?

    Second, what does "determine if I need to roll the log not" mean?


    -- Bill Stewart [Bill_Stewart]

    Monday, October 29, 2018 5:10 PM
    Moderator
  • After a log file reaches a given size I want to roll the log file. OutLog.log --> OutLog-001.log etc.

    I've found what I needed.

    $fdFile.BaseStream.Length gives me the size on a live ongoing basis. Gotta love Powershell.  :-)


    -- Tim.

    Monday, October 29, 2018 5:55 PM