mjg Posted September 29, 2007 Posted September 29, 2007 I'm in need of some data manipulation with array 1 of the FileGetShortCut function. What information I need is the last few numbers of the working directory path (which could be 1-999 with no preceding 0's). So basically my working directory might look like this: c:\heh\node\node23 and what information I would like to put into a variable is 23 and drop the rest. Can anyone point me in the right direction? -mjg
Siao Posted September 29, 2007 Posted September 29, 2007 (edited) StringRegExp($str, "(\d+)\z", 1) to get all numbers from the end of the string. StringRegExp($str, "\D([1-9]\d{0,2})\z", 1) to get numbers from the end of the string, only if it's in the range 1-999. Edited September 29, 2007 by Siao "be smart, drink your wine"
mjg Posted September 29, 2007 Author Posted September 29, 2007 Great, thanks for pointing that function out to me; however, for some reason I'm getting nothing returned. Here is my code, so maybe I'm a bit out of whack there: ;start of really test sloppy script $nodeinfo = FileGetShortcut(@DesktopDir &"\calc.lnk") $heh = $details[1] ; this currently returns c:\heh\node\node32 MsgBox(0,$heh, $heh) ; to verify it is getting the correct string $nodeonly = StringRegExp($heh, "\D([1-9]\d{0,2})\z", 1) ; suggested code MsgBox(0,"heh", $nodeonly) ; returns a blank
BrettF Posted September 29, 2007 Posted September 29, 2007 Ok... So if we have this: #include <Array.au3> FileCreateShortcut (@SystemDir & "\system32\calc.exe", @DesktopDir &"\calc12.lnk") ;start of really test sloppy script $details = FileGetShortcut(@DesktopDir &"\calc12.lnk") If Not IsArray ($details) Then Exit $heh = $details[1]; this currently returns c:\heh\node\node32 _ArrayDisplay ($details) MsgBox(0,$heh, $heh); to verify it is getting the correct string $nodeonly = StringRegExp($heh, "\D([1-9]\d{0,2})\z", 1); suggested code MsgBox(0,"heh", $nodeonly); returns a blank And we take a closer look at it, and add the _ArrayDisplay and IsArray to $details, we can see that $nodeonly isn't finding a match, so thats why it returns 0. Also, The Value of $details[1] is the working directory. which in this case, returns nothing. Well for me at least. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
mjg Posted September 29, 2007 Author Posted September 29, 2007 Well, for my working directory I have manually inputted c:\heh\node\node32 So when I use your script, I do see row [1] as c:\heh\node\node32 What i'm hoping to get is just the 32 into some sort of variable. -mjg
BrettF Posted September 29, 2007 Posted September 29, 2007 (edited) This worked: #include <Array.au3> FileCreateShortcut (@SystemDir & "\system32\calc.exe", @DesktopDir &"\calc12.lnk", "c:\heh\node\node32") ;start of really test sloppy script $details = FileGetShortcut(@DesktopDir &"\calc12.lnk") If Not IsArray ($details) Then Exit $heh = $details[1]; this currently returns c:\heh\node\node32 _ArrayDisplay ($details) MsgBox(0,$heh, $heh); to verify it is getting the correct string $string = StringSplit ($heh, "\") $nodeonly = StringRegExp($string[$string[0]], "(\d+)\z", 1); suggested code MsgBox (0, "", $string[$string[0]]) _ArrayDisplay ($nodeonly) MsgBox(0,"heh", $nodeonly[0]); returns a blank The string split is unnecessary... This is better: #include <Array.au3> FileCreateShortcut (@SystemDir & "\system32\calc.exe", @DesktopDir &"\calc12.lnk", "c:\heh\node\node32") ;start of really test sloppy script $details = FileGetShortcut(@DesktopDir &"\calc12.lnk") If Not IsArray ($details) Then Exit $heh = $details[1]; this currently returns c:\heh\node\node32 _ArrayDisplay ($details) MsgBox(0,$heh, $heh); to verify it is getting the correct string $nodeonly = StringRegExp($heh, "(\d+)\z", 1); suggested code _ArrayDisplay ($nodeonly) MsgBox(0,"heh", $nodeonly[0]); returns a blank Edited September 29, 2007 by Bert Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Siao Posted September 29, 2007 Posted September 29, 2007 (edited) Ok, lets spoonfeed this baby... $str = "c:\heh\node\node32" $a = StringRegExp($str, "\D([1-9]\d{0,2})\z", 1) If @error Then MsgBox(0,'','Not found.') Else MsgBox(0,'',$a[0]) EndIf Edited September 30, 2007 by Siao "be smart, drink your wine"
mjg Posted September 30, 2007 Author Posted September 30, 2007 Perfect, thank you all very much. -mjg
BrettF Posted September 30, 2007 Posted September 30, 2007 Ok, lets spoonfeed this baby...Sounds great... Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
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