jlandes Posted January 27, 2005 Posted January 27, 2005 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
SvenP Posted January 27, 2005 Posted January 27, 2005 (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 FunctionAny 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 January 27, 2005 by SvenP
Valik Posted January 27, 2005 Posted January 27, 2005 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.
jlandes Posted January 27, 2005 Author Posted January 27, 2005 Do you mind if I include these functions of your in File.au3 in the standard library? Sincerely yours,Jeremy Landesjlandes@landeserve.com
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