Sign in to follow this  
Followers 0
avery

Last element in an Array

8 posts in this topic

Func select_file1()
    $file1 = FileOpenDialog("Select Source File", "", "All (*.*)", 1 + 4)
    GUICtrlSetData($file1_input,$file1)
    
    $file1a = StringSplit($file1, "\")
    MsgBox(4, "MD5", $file1a[1])
   ;MsgBox(4, "MD5", $file1a[-1]) -- ERRORS :( 

    ...
    ...
EndFunc

Hello,

I'm trying to get the filename from the entire path -- code above. Can anyone please help me determine the total elements in an array so I can jump to the last one? Is there a better way to do this?

ADVthanksANCE

-avery


www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

-1 Holds no data, 0 holds how many is in there so they this:

$String = StringSplit($File1, "\")
$Path = $String[$String[0]]
MsgBox(0, "$Path = ", $Path)

EDIT: But of course this will fail if they hit the X or something, so use error checking too!

Edited by JasonB

Share this post


Link to post
Share on other sites

Try

MsgBox(4, "MD5", $file1a[ubound($file1a)-1])

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the fast help. I'm moving forward again ;-)

Did they both work? :)

Seems as Kerros didn't work.

Edited by JasonB

Share this post


Link to post
Share on other sites

why wouldn't that work?

Local $file1a[7] = ['John Doe','Jane Sam','Billy Bob','Tom Jones','Frank','Mary','Lew']


MsgBox(4, "MD5", $file1a[ubound($file1a)-1])

That gives you a message box with "Lew"


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites

Ah, I was using it wrong!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

why wouldn't that work?

Local $file1a[7] = ['John Doe','Jane Sam','Billy Bob','Tom Jones','Frank','Mary','Lew']


MsgBox(4, "MD5", $file1a[ubound($file1a)-1])

That gives you a message box with "Lew"

I used the unbound method at first until I realized the reason the MD5 checksums changed when the path did was due to me using the UDF (user defined function?) in string mode not file.

The short answer: I didn't end up using either one but none the less I learned a great deal in the process.

Thanks again :)

edit: I take that back -- I kept the Split for the Logfile text I generate :P

Edited by avery

www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org

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