Jump to content

Recommended Posts

Posted

Is there an equivalent function in AutoIt to VB's InStrRev() function? I want to conver the following VB code to AutoIt code for inclusion in the standard library:

' Get the filename
Function GetFileName(strPath As String)
    GetFileName = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function

' Get the path
Function GetFilePath(strPath As String)
    GetFilePath = Mid(strPath, 1, InStrRev(strPath, "\") - 1)
End Function

' Get the file extension
Function GetFileExt(strPath As String)
    GetFileExt = Mid(strPath, InStrRev(strPath, "."))
End Function

' Get the file drive
Function GetFileDrive(strPath As String)
    GetFileDrive = Mid(strPath, 1, InStr(1, strPath, "\") - 1)
End Function

Any help would be greatly appreciated. Thanks.

Sincerely yours,Jeremy Landesjlandes@landeserve.com

Posted (edited)

Is there an equivalent function in AutoIt to VB's InStrRev() function?  I want to conver the following VB code to AutoIt code for inclusion in the standard library:

' Get the filename
Function GetFileName(strPath As String)
    GetFileName = Mid(strPath, InStrRev(strPath, "\") + 1)
.......
End Function

Any help would be greatly appreciated.  Thanks.

<{POST_SNAPBACK}>

In AutoIt it's StringInStr() with it's last parameter -1. See the helpfile on that function.

So to get only the filename from a full path, you could do:

$FilenameOnly=StringRight($FileName,StringLen($FileName)-StringInStr($Filename,"\",0,-1))

Regards,

-Sven

Edited by SvenP
Posted

Jeremy, that code makes a lot of assumptions. I hope you aren't making a straight port. You should have a look at my path.au3 functions. _SplitPath(), specifically, could be wrapped to implement those 4 functions. Otherwise, a Unix path will break that function since it assumes a \ instead of /. My functions also support UNC paths.

Posted

Do you mind if I include these functions of your in File.au3 in the standard library?

Sincerely yours,Jeremy Landesjlandes@landeserve.com

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
  • Recently Browsing   0 members

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