Jump to content
31290

Extract "never the same" string from filename

Recommended Posts

31290

Hi everyone :)

Hope you're doing great today. ;)

Well, I have a little question about extracting a certain string from a file name to make comparison after treatment.

Let's get into the details:

First of all, I gather and store a machine BIOS Version by running this:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, "$STDOUT_CHILD")
_FileWriteToLine("c:\Drivers\BIOS_Version.txt", 1, "", 1)
$sContent = FileRead ("C:\Drivers\BIOS_Version.txt")
$sContent = StringRegExpReplace($sContent, " ", "")

Result is, for example, A10

Then, I download the latest available BIOS version from the Dell related model website and the filename of the latest BIOS is stored in a $sBIOSName variable.

Result is for example, E5440A14.exe

What i can't figure out is how to extract the Bios name stored in the $sBIOSName knowing that each model this app would run won't have the same number of chars.
Indeed, I have some OPL790AXX.exe / OPL7010AXX.exe / E5470AXX.exe etc...

I imagine something like getting the whole string, left trimming it to the first A found count 2 chars on the right and store them to have the possibility to make the check between A10 and A14 (as the number of char of filenames is never the same)

Hope this is clear :) If not, don't hesitate to ask for more.
Thanks in advance for the help :)

 

Edited by 31290

~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites
water

Use StringInStr to get the position of the first "A" and then use this as starting position for your calculation.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
31290

Hi Water :)

Thanks for the reply.

Indeed, I just found this way to do so:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, "$STDOUT_CHILD")
_FileWriteToLine("c:\Drivers\BIOS_Version.txt", 1, "", 1)
$sContent = FileRead ("C:\Drivers\BIOS_Version.txt")
$sContent = StringRegExpReplace($sContent, " ", "")
$sMidBIOSNAME = StringInStr ($sBIOSName, "A")
$sFinalBIOSNAME = StringMid($sBIOSName, $sMidBIOSNAME, 3)
msgbox (0, "", $sFinalBIOSNAME)

I got the expected result. 

Do you think this can be optimized / shortened or not? (just curious ^^)


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites
water

RegExp's are most of the time shorter than regular AutoIt functions. But don't forget to add comments so you still know what the RegExp does in a few months.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
jguinch

I know it's not the question, but you should get the BIOS version directly from the registry :

Func _BiosVersion()
    Return RegRead("HKLM\HARDWARE\DESCRIPTION\System\BIOS", "BIOSVersion")
EndFunc

 

Share this post


Link to post
Share on other sites
Danyfirex

Hello. Just for fun.

 

$str = "   OPL790A12.exe   "
Msgbox(0,"",StringMid($str,StringInStr($str,".exe")-3,3))

Saludos

Share this post


Link to post
Share on other sites
water

Or use "Scriptomatic" to generate the WMI query for you. It assigns the result to an variable or array.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
VIP

Script get the version wrong syntax:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, "$STDOUT_CHILD")

TO:

RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION" & @CRLF, "", @SW_HIDE, $STDOUT_CHILD)
;::OR
RunWait(@ComSpec & " /c " & "wmic bios get SMBIOSBIOSVERSION >> C:\Drivers\Tag.txt" & @CRLF, "", @SW_HIDE, $STDOUT_CHILD)

and something useful:

Local $iPID = Run('"' & @ComSpec & '" /c ' & 'wmic bios get SMBIOSBIOSVERSION', '', @SW_HIDE, 0x2) ;$STDOUT_CHILD (0x2)
ProcessWaitClose($iPID)
Local $sSMBIOSBIOSVersion = StdoutRead($iPID)
$sSMBIOSBIOSVersion = StringStripWS(StringReplace(StringReplace($sSMBIOSBIOSVersion, "SMBIOSBIOSVersion", ""), " ", ""), 8)

Local $hFileOpen = FileOpen("C:\Drivers\BIOS_Version.txt", 2 + 8)
FileWrite($hFileOpen, $sSMBIOSBIOSVersion)
FileClose($hFileOpen)

ConsoleWrite($sSMBIOSBIOSVersion & @CRLF)
;~ ConsoleWrite(@CRLF & _WMI_SingleQuery("Win32_BIOS", "Manufacturer") & @CRLF)
;~ ConsoleWrite(@CRLF & _WMI_SingleQuery("Win32_BIOS", "SMBIOSBIOSVERSION") & @CRLF)
;~ ConsoleWrite(@CRLF & _BIOSinfo() & @CRLF)

Func _BIOSinfo($sComputer = ".")
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sComputer & "\root\CIMV2")
    Local $Output, $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", 0x10 + 0x20)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $Output &= $objItem.BIOSVersion(0) & @CR
            $Output &= $objItem.Manufacturer & @CR
            $Output &= $objItem.SMBIOSBIOSVersion
            Return $Output
        Next
    EndIf
EndFunc   ;==>_BIOSinfo

Func _WMI_SingleQuery($sClass, $sProperty, $sComputer = ".")
    Local $objWMI = ObjGet("winmgmts:\\" & $sComputer & "\root\CIMV2")
    Local $objInstances = $objWMI.InstancesOf($sClass)
    Local $count = $objInstances.Count
    If @error Or Not $count Then Return SetError(1, 0, "") ;"Object Error"
    For $objItem In $objInstances
        For $objProperties In $objItem.Properties_()
            If ($objProperties.Name = $sProperty) Then Return $objProperties.Value
        Next
    Next
    Return SetError(2, 0, "") ;"Nothing Found"
EndFunc   ;==>_WMI_SingleQuery

 


Regards,
 

Share this post


Link to post
Share on other sites
31290

Many thanks all for your inputs, much appreciated!

Have a great day!


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
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

  • Similar Content

    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
    • nacerbaaziz
      By nacerbaaziz
      Hello Members of this best Forum
      i have a question please
      for example if i have a long string
      and i want to extract a text between two tag
      what i can do to make that?
      note :
      i know that there is a
      StringRegExp function
      it's do that work
      but it result is be as an array
      i want the result to be a string
      is there any function on autoit can do that?
      Thanks in advance.
×