Jump to content

Last element in an Array


Recommended Posts

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
Link to comment
Share on other sites

-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
Link to comment
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.

Link to comment
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.

Link to comment
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"

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...