Jump to content

Read/Capture the "Free" space from Diskpart "List Disk" output


Recommended Posts

Hey guys, what would be the best way to extract/read the following value from a diskpart, list disk, text file. I have a gui that the person specifies the disk number they want to use. Problem is, I need to extract the "Free" space value based off their Disk Input. Any ideas of the best way to do this?

Here is what I am exporting to a basic text file right now. If the user inputs the number 3 on my input box, I want to read the file and pull back the value 7167. If they entered 2 I want to pull back 4095. I have looked at things like StringRegExp and _StringExplode, but not sure or very experienced in that, or even sure if that is what I should be doing for this scenario. Any ideas, input, or examples would be greatly appreciated.

  Disk ###  Status         Size     Free     Dyn  Gpt

  --------  -------------  -------  -------  ---  ---
  Disk 0    Online           60 GB  1024 KB         
  Disk 1    Online          100 GB    10 GB         
  Disk 2    Online         4096 GB  4095 GB        *
  Disk 3    Online         7168 GB  7167 GB        *

Link to comment
Share on other sites

This should work

$s = FileRead("1.txt")

$n = "2"

; $r = StringRegExpReplace($s, '(?s).*Disk\h+' & $n & '\N+\h(\d+\h+[KG]B)\h+\D.*', "$1")  ; value + GB
$r = StringRegExpReplace($s, '(?s).*Disk\h+' & $n & '\N+\h(\d+)\h+[KG]B\h+\D.*', "$1")   ; value only
Msgbox(0,"", $r)

But if the columns are TAB separated in the file there is probably a simpler way

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...