udfFileRootExt
str udfFileRootExt (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_1 (strFilePath)
Return StrCat (FileRoot (strFilePath), StrSub (".", 1, FileExtension (strFilePath) != ""), FileExtension (strFilePath))
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_2 (strFilePath)
Return StrReplace (strFilePath, FilePath (strFilePath), "")
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_3 (strFilePath)
Return ItemExtract (-1, ItemExtract (-1, strFilePath, ":"), "\")
#EndFunction
; This seems to be resp. this was the fastest method before FileBaseName was implemented as a native function.
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_4 (strFilePath)
Return FileBaseName (strFilePath, 0) ; 0 = (default) do not include a dot '.' on the end of a filename with no extension.

#EndFunction
; This should be the fastest method, wrapped into udf just for the performancetest.
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_5 (strFilePath)
Return FileBaseName (strFilePath, 1) ; 1 = include a dot '.' on the end of a filename with no extension.

#EndFunction
; This should be the fastest method, wrapped into udf just for the performancetest.
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfPathStripPath (strFilePath) ; JustFilename
If strFilePath == "" Then Return ""
intMAX_PATH = 260
hdlBB = BinaryAlloc (intMAX_PATH)
BinaryPokeStr (hdlBB, 0, strFilePath)
intResult = DllCall (StrCat (DirWindows (1), "SHLWAPI.DLL"), long:"PathStripPathA", lpbinary:hdlBB)
strFilePath = BinaryPeekStr (hdlBB, 0, intMAX_PATH)
hdlBB = BinaryFree (hdlBB)
Return strFilePath
;..........................................................................................................................................
; Removes the path portion of a fully qualified path and file.
; Detlev Dalitz.20010807
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strFilename101 = udfPathStripPath ("D:\TEMP\TEST.TXT")             ; "TEST.TXT"
strFilename102 = udfPathStripPath ("\\XXX\X\TEMP TEMP\TEST.TXT")   ; "TEST.TXT"
strFilename103 = udfPathStripPath ("\\XXX\X\TEMP TEMP\TEST.")      ; "TEST."
strFilename104 = udfPathStripPath ("\\XXX\X\TEMP TEMP\.")          ; "."
strFilename105 = udfPathStripPath ("\\XXX\X\TEMP TEMP\..")         ; ".."
strFilename106 = udfPathStripPath ("\\XXX\X\TEMP TEMP\...")        ; "..."
strFilename107 = udfPathStripPath ("\\XXX\X\TEMP TEMP\....")       ; "...."
strFilename108 = udfPathStripPath ("\\XXX\X\TEMP TEMP\TEST")       ; "TEST"
strFilename109 = udfPathStripPath ("\\XXX\X\TEMP TEMP\")           ; "TEMP TEMP\"
strFilename110 = udfPathStripPath ("\\XXX\X\TEMP TEMP")            ; "TEMP TEMP"
strFilename111 = udfPathStripPath ("\\XXX\X\")                     ; "X\"
strFilename112 = udfPathStripPath ("\\XXX\X")                      ; "X"
strFilename113 = udfPathStripPath ("\\XXX\")                       ; "XXX\"
strFilename114 = udfPathStripPath ("\\XXX")                        ; "XXX"
strFilename115 = udfPathStripPath ("\\")                           ; "\\"
strFilename116 = udfPathStripPath ("\")                            ; "\"
strFilename117 = udfPathStripPath ("")                             ; ""
strFilename118 = udfPathStripPath ("D:TEST.TXT")                   ; "TEST.TXT"

strFilename201 = udfFileRootExt_1 ("D:\TEMP\TEST.TXT")             ; "TEST.TXT"
strFilename202 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\TEST.TXT")   ; "TEST.TXT"
strFilename203 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\TEST.")      ; "TEST"
strFilename204 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\.")          ; ""
strFilename205 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\..")         ; "."
strFilename206 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\...")        ; ".."
strFilename207 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\....")       ; "..."
strFilename208 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\TEST")       ; "TEST"
strFilename209 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\")           ; ""
strFilename210 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP")            ; "TEMP TEMP"
strFilename211 = udfFileRootExt_1 ("\\XXX\X\")                     ; ""
strFilename212 = udfFileRootExt_1 ("\\XXX\X")                      ; "X"
strFilename213 = udfFileRootExt_1 ("\\XXX\")                       ; ""
strFilename214 = udfFileRootExt_1 ("\\XXX")                        ; "XXX"
strFilename215 = udfFileRootExt_1 ("\\")                           ; ""
strFilename216 = udfFileRootExt_1 ("\")                            ; ""
strFilename217 = udfFileRootExt_1 ("")                             ; ""
strFilename218 = udfFileRootExt_1 ("D:TEST.TXT")                   ; "TEST.TXT"

strFilename301 = udfFileRootExt_2 ("D:\TEMP\TEST.TXT")             ; "TEST.TXT"
strFilename302 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\TEST.TXT")   ; "TEST.TXT"
strFilename303 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\TEST.")      ; "TEST."
strFilename304 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\.")          ; "."
strFilename305 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\..")         ; ".."
strFilename306 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\...")        ; "..."
strFilename307 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\....")       ; "...."
strFilename308 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\TEST")       ; "TEST"
strFilename309 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\")           ; ""
strFilename310 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP")            ; "TEMP TEMP"
strFilename311 = udfFileRootExt_2 ("\\XXX\X\")                     ; ""
strFilename312 = udfFileRootExt_2 ("\\XXX\X")                      ; "X"
strFilename313 = udfFileRootExt_2 ("\\XXX\")                       ; ""
strFilename314 = udfFileRootExt_2 ("\\XXX")                        ; "XXX"
strFilename315 = udfFileRootExt_2 ("\\")                           ; ""
strFilename316 = udfFileRootExt_2 ("\")                            ; ""
strFilename317 = udfFileRootExt_2 ("")                             ; ""
strFilename318 = udfFileRootExt_2 ("D:TEST.TXT")                   ; "TEST.TXT"

strFilename401 = udfFileRootExt_3 ("D:\TEMP\TEST.TXT")             ; "TEST.TXT"
strFilename402 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\TEST.TXT")   ; "TEST.TXT"
strFilename403 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\TEST.")      ; "TEST."
strFilename404 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\.")          ; "."
strFilename405 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\..")         ; ".."
strFilename406 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\...")        ; "..."
strFilename407 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\....")       ; "...."
strFilename408 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\TEST")       ; "TEST"
strFilename409 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\")           ; ""
strFilename410 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP")            ; "TEMP TEMP"
strFilename411 = udfFileRootExt_3 ("\\XXX\X\")                     ; ""
strFilename412 = udfFileRootExt_3 ("\\XXX\X")                      ; "X"
strFilename413 = udfFileRootExt_3 ("\\XXX\")                       ; ""
strFilename414 = udfFileRootExt_3 ("\\XXX")                        ; "XXX"
strFilename415 = udfFileRootExt_3 ("\\")                           ; ""
strFilename416 = udfFileRootExt_3 ("\")                            ; ""
strFilename417 = udfFileRootExt_3 ("")                             ; ""
strFilename418 = udfFileRootExt_3 ("D:TEST.TXT")                   ; "TEST.TXT"

strFilename501 = udfFileRootExt_4 ("D:\TEMP\TEST.TXT")             ; "TEST.TXT"
strFilename502 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\TEST.TXT")   ; "TEST.TXT"
strFilename503 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\TEST.")      ; "TEST"
strFilename504 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\.")          ; ""
strFilename505 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\..")         ; "."
strFilename506 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\...")        ; ".."
strFilename507 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\....")       ; "..."
strFilename508 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\TEST")       ; "TEST"
strFilename509 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\")           ; ""
strFilename510 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP")            ; "TEMP TEMP"
strFilename511 = udfFileRootExt_4 ("\\XXX\X\")                     ; ""
strFilename512 = udfFileRootExt_4 ("\\XXX\X")                      ; "X"
strFilename513 = udfFileRootExt_4 ("\\XXX\")                       ; ""
strFilename514 = udfFileRootExt_4 ("\\XXX")                        ; "XXX"
strFilename515 = udfFileRootExt_4 ("\\")                           ; ""
strFilename516 = udfFileRootExt_4 ("\")                            ; ""
strFilename517 = udfFileRootExt_4 ("")                             ; ""
strFilename518 = udfFileRootExt_4 ("D:TEST.TXT")                   ; "TEST.TXT"

strFilename601 = udfFileRootExt_5 ("D:\TEMP\TEST.TXT")             ; "TEST.TXT"
strFilename602 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\TEST.TXT")   ; "TEST.TXT"
strFilename603 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\TEST.")      ; "TEST."
strFilename604 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\.")          ; "."
strFilename605 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\..")         ; ".."
strFilename606 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\...")        ; "..."
strFilename607 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\....")       ; "...."
strFilename608 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\TEST")       ; "TEST."
strFilename609 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\")           ; "."
strFilename610 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP")            ; "TEMP TEMP."
strFilename611 = udfFileRootExt_5 ("\\XXX\X\")                     ; "."
strFilename612 = udfFileRootExt_5 ("\\XXX\X")                      ; "X."
strFilename613 = udfFileRootExt_5 ("\\XXX\")                       ; "."
strFilename614 = udfFileRootExt_5 ("\\XXX")                        ; "XXX".
strFilename615 = udfFileRootExt_5 ("\\")                           ; "."
strFilename616 = udfFileRootExt_5 ("\")                            ; "."
strFilename617 = udfFileRootExt_5 ("")                             ; "."
strFilename618 = udfFileRootExt_5 ("D:TEST.TXT")                   ; "TEST.TXT"


;------------------------------------------------------------------------------------------------------------------------------------------
:Performancetest
strMsgTitle = "Demo Performance Test"

strURL = "\\SERVER\SHARE\FOLDER\FILENAME.EXT"


intTestLoop = 1000

intMaxTests = 6

intTest = 1
Display (1, strMsgTitle, "Running Test %intTest%, please wait ...")
Exclusive (@ON)
intStart = GetTickCount ()
For intLoop = 1 To intTestLoop
   Result = udfPathStripPath (strURL)
Next
intStop = GetTickCount ()
Exclusive (@OFF)
intTicks%intTest% = intStop - intStart

intTest = 2
Display (1, strMsgTitle, "Running Test %intTest%, please wait ...")
Exclusive (@ON)
intStart = GetTickCount ()
For intLoop = 1 To intTestLoop
   Result = udfFileRootExt_1 (strURL)
Next
intStop = GetTickCount ()
Exclusive (@OFF)
intTicks%intTest% = intStop - intStart

intTest = 3
Display (1, strMsgTitle, "Running Test %intTest%, please wait ...")
Exclusive (@ON)
intStart = GetTickCount ()
For intLoop = 1 To intTestLoop
   Result = udfFileRootExt_2 (strURL)
Next
intStop = GetTickCount ()
Exclusive (@OFF)
intTicks%intTest% = intStop - intStart

intTest = 4
Display (1, strMsgTitle, "Running Test %intTest%, please wait ...")
Exclusive (@ON)
intStart = GetTickCount ()
For intLoop = 1 To intTestLoop
   Result = udfFileRootExt_3 (strURL)
Next
intStop = GetTickCount ()
Exclusive (@OFF)
intTicks%intTest% = intStop - intStart

intTest = 5
Display (1, strMsgTitle, "Running Test %intTest%, please wait ...")
Exclusive (@ON)
intStart = GetTickCount ()
For intLoop = 1 To intTestLoop
   Result = udfFileRootExt_4 (strURL)
Next
intStop = GetTickCount ()
Exclusive (@OFF)
intTicks%intTest% = intStop - intStart


intTest = 6
Display (1, strMsgTitle, "Running Test %intTest%, please wait ...")
Exclusive (@ON)
intStart = GetTickCount ()
For intLoop = 1 To intTestLoop
   Result = udfFileRootExt_5 (strURL)
Next
intStop = GetTickCount ()
Exclusive (@OFF)
intTicks%intTest% = intStop - intStart



intMaxTicks = 0
For intTest = 1 To intMaxTests
   intMaxTicks = Max (intMaxTicks, intTicks%intTest%)
Next
For intTest = 1 To intMaxTests
   intPct%intTest% = 100 * intTicks%intTest% / intMaxTicks
Next
strMsgText = ""
For intTest = 1 To intMaxTests
   strMsgText = StrCat (strMsgText, "Test ", intTest, @TAB, "Ticks = ", @TAB, intTicks%intTest%, @TAB, intPct%intTest%, " %%", @CRLF)
Next
Message (strMsgTitle, strMsgText)
ClipPut (strMsgText)

Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;   Test 1   Ticks = 1188   100 %
;   Test 2   Ticks =  562    47 %
;   Test 3   Ticks =  391    32 %
;   Test 4   Ticks =  344    28 %  <==
;   Test 5   Ticks =  328    27 %  <==
;   Test 6   Ticks =  312    26 %  <==
;------------------------------------------------------------------------------------------------------------------------------------------