donhorn20 Posted October 9, 2016 Share Posted October 9, 2016 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 More sharing options...
mikell Posted October 9, 2016 Share Posted October 9, 2016 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 donhorn20 1 Link to comment Share on other sites More sharing options...
donhorn20 Posted October 10, 2016 Author Share Posted October 10, 2016 Thanks mikell, this worked wonderfully and was exactly what I was looking for. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now