none
Reading large binary files RRS feed

  • Question

  • Hi, I’m a beginner in PowerShell scripting. I want to read a binary file, I can skip to a position and read one byte, but I can’t read two bytes, I don’t know how to give the buffer for the read operation, I don’t want to use C#. Can somebody show a little snippet how to skip to, e.g., 603761 and read 1024 bytes? Preferably to show where it is documented and where I can find similar sample scripts. I’ve looked a few dozen threads on this forum, no luck.
    Thanks, Vilmos

    Tuesday, January 8, 2013 5:31 PM

Answers

  • $file = "C\bigfile.rar"
    $buf = new-object byte[] 1024
    $fs = new-object IO.FileStream($file, [IO.FileMode]::Open)
    $reader = new-object IO.BinaryReader($fs)
    $reader.BaseStream.Seek(603761,"Begin")
    $reader.Read($buf, 0, 1024)
    $reader.Close()

    Tuesday, January 8, 2013 6:46 PM

All replies

  • $file = "C\bigfile.rar"
    $buf = new-object byte[] 1024
    $fs = new-object IO.FileStream($file, [IO.FileMode]::Open)
    $reader = new-object IO.BinaryReader($fs)
    $reader.BaseStream.Seek(603761,"Begin")
    $reader.Read($buf, 0, 1024)
    $reader.Close()

    Tuesday, January 8, 2013 6:46 PM
  • Thanks Kazun, Vilmos
    Tuesday, January 8, 2013 11:55 PM