Sign in to follow this  
Followers 0
mjg

FileGetShortCut data manipulation

9 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Bert

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Perfect, thank you all very much.

-mjg

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
Sign in to follow this  
Followers 0