udfPathStripPath (sPathStr)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_1 (sPathStr)
Return StrCat(FileRoot(sPathStr),StrSub(".",1,FileExtension(sPathStr)>""),FileExtension(sPathStr))
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_2 (sPathStr)
Return StrReplace(sPathStr,FilePath(sPathStr),"")
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_3 (sPathStr)
Return ItemExtract(-1,ItemExtract(-1,sPathStr,":"),"\")
#EndFunction
; This seems to be resp. this was the fastest method
; before FileBaseName was implemented as a native function.
;------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_4 (sPathStr)
Return FileBaseName(sPathStr,0)
#EndFunction
; This should be the fastest method, wrapped into udf just for the performancetest.
;------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileRootExt_5 (sPathStr)
Return FileBaseName(sPathStr,1)
#EndFunction
; This should be the fastest method, wrapped into udf just for the performancetest.
;------------------------------------------------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfPathStripPath (sPathStr) ; JustFilename
If (sPathStr=="") Then Return (sPathStr)
iMAX_PATH = 260
hBB = BinaryAlloc(iMAX_PATH)
BinaryPokeStr(hBB,0,sPathStr)
iResult = DllCall(StrCat(DirWindows(1),"SHLWAPI.DLL"),long:"PathStripPathA",lpbinary:hBB)
sPathStr = BinaryPeekStr(hBB,0,iMAX_PATH)
BinaryFree(hBB)
Return (sPathStr)
; Removes the path portion of a fully qualified path and file.
; Detlev Dalitz.20010807
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
; --- test ---
sFilename101 = udfPathStripPath ("D:\TEMP\TEST.TXT") ; "TEST.TXT"
sFilename102 = udfPathStripPath ("\\XXX\X\TEMP TEMP\TEST.TXT") ; "TEST.TXT"
sFilename103 = udfPathStripPath ("\\XXX\X\TEMP TEMP\TEST.") ; "TEST."
sFilename104 = udfPathStripPath ("\\XXX\X\TEMP TEMP\.") ; "."
sFilename105 = udfPathStripPath ("\\XXX\X\TEMP TEMP\..") ; ".."
sFilename106 = udfPathStripPath ("\\XXX\X\TEMP TEMP\...") ; "..."
sFilename107 = udfPathStripPath ("\\XXX\X\TEMP TEMP\....") ; "...."
sFilename108 = udfPathStripPath ("\\XXX\X\TEMP TEMP\TEST") ; "TEST"
sFilename109 = udfPathStripPath ("\\XXX\X\TEMP TEMP\") ; "TEMP TEMP\"
sFilename110 = udfPathStripPath ("\\XXX\X\TEMP TEMP") ; "TEMP TEMP"
sFilename111 = udfPathStripPath ("\\XXX\X\") ; "X\"
sFilename112 = udfPathStripPath ("\\XXX\X") ; "X"
sFilename113 = udfPathStripPath ("\\XXX\") ; "XXX\"
sFilename114 = udfPathStripPath ("\\XXX") ; "XXX"
sFilename115 = udfPathStripPath ("\\") ; "\\"
sFilename116 = udfPathStripPath ("\") ; "\"
sFilename117 = udfPathStripPath ("") ; ""
sFilename118 = udfPathStripPath ("D:TEST.TXT") ; "TEST.TXT"
sFilename201 = udfFileRootExt_1 ("D:\TEMP\TEST.TXT") ; "TEST.TXT"
sFilename202 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\TEST.TXT") ; "TEST.TXT"
sFilename203 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\TEST.") ; "TEST"
sFilename204 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\.") ; ""
sFilename205 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\..") ; "."
sFilename206 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\...") ; ".."
sFilename207 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\....") ; "..."
sFilename208 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\TEST") ; "TEST"
sFilename209 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP\") ; ""
sFilename210 = udfFileRootExt_1 ("\\XXX\X\TEMP TEMP") ; "TEMP TEMP"
sFilename211 = udfFileRootExt_1 ("\\XXX\X\") ; ""
sFilename212 = udfFileRootExt_1 ("\\XXX\X") ; "X"
sFilename213 = udfFileRootExt_1 ("\\XXX\") ; ""
sFilename214 = udfFileRootExt_1 ("\\XXX") ; "XXX"
sFilename215 = udfFileRootExt_1 ("\\") ; ""
sFilename216 = udfFileRootExt_1 ("\") ; ""
sFilename217 = udfFileRootExt_1 ("") ; ""
sFilename218 = udfFileRootExt_1 ("D:TEST.TXT") ; "TEST.TXT"
sFilename301 = udfFileRootExt_2 ("D:\TEMP\TEST.TXT") ; "TEST.TXT"
sFilename302 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\TEST.TXT") ; "TEST.TXT"
sFilename303 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\TEST.") ; "TEST."
sFilename304 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\.") ; "."
sFilename305 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\..") ; ".."
sFilename306 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\...") ; "..."
sFilename307 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\....") ; "...."
sFilename308 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\TEST") ; "TEST"
sFilename309 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP\") ; ""
sFilename310 = udfFileRootExt_2 ("\\XXX\X\TEMP TEMP") ; "TEMP TEMP"
sFilename311 = udfFileRootExt_2 ("\\XXX\X\") ; ""
sFilename312 = udfFileRootExt_2 ("\\XXX\X") ; "X"
sFilename313 = udfFileRootExt_2 ("\\XXX\") ; ""
sFilename314 = udfFileRootExt_2 ("\\XXX") ; "XXX"
sFilename315 = udfFileRootExt_2 ("\\") ; ""
sFilename316 = udfFileRootExt_2 ("\") ; ""
sFilename317 = udfFileRootExt_2 ("") ; ""
sFilename318 = udfFileRootExt_2 ("D:TEST.TXT") ; "TEST.TXT"
sFilename401 = udfFileRootExt_3 ("D:\TEMP\TEST.TXT") ; "TEST.TXT"
sFilename402 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\TEST.TXT") ; "TEST.TXT"
sFilename403 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\TEST.") ; "TEST."
sFilename404 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\.") ; "."
sFilename405 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\..") ; ".."
sFilename406 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\...") ; "..."
sFilename407 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\....") ; "...."
sFilename408 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\TEST") ; "TEST"
sFilename409 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP\") ; ""
sFilename410 = udfFileRootExt_3 ("\\XXX\X\TEMP TEMP") ; "TEMP TEMP"
sFilename411 = udfFileRootExt_3 ("\\XXX\X\") ; ""
sFilename412 = udfFileRootExt_3 ("\\XXX\X") ; "X"
sFilename413 = udfFileRootExt_3 ("\\XXX\") ; ""
sFilename414 = udfFileRootExt_3 ("\\XXX") ; "XXX"
sFilename415 = udfFileRootExt_3 ("\\") ; ""
sFilename416 = udfFileRootExt_3 ("\") ; ""
sFilename417 = udfFileRootExt_3 ("") ; ""
sFilename418 = udfFileRootExt_3 ("D:TEST.TXT") ; "TEST.TXT"
sFilename501 = udfFileRootExt_4 ("D:\TEMP\TEST.TXT") ; "TEST.TXT"
sFilename502 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\TEST.TXT") ; "TEST.TXT"
sFilename503 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\TEST.") ; "TEST"
sFilename504 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\.") ; ""
sFilename505 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\..") ; "."
sFilename506 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\...") ; ".."
sFilename507 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\....") ; "..."
sFilename508 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\TEST") ; "TEST"
sFilename509 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP\") ; ""
sFilename510 = udfFileRootExt_4 ("\\XXX\X\TEMP TEMP") ; "TEMP TEMP"
sFilename511 = udfFileRootExt_4 ("\\XXX\X\") ; ""
sFilename512 = udfFileRootExt_4 ("\\XXX\X") ; "X"
sFilename513 = udfFileRootExt_4 ("\\XXX\") ; ""
sFilename514 = udfFileRootExt_4 ("\\XXX") ; "XXX"
sFilename515 = udfFileRootExt_4 ("\\") ; ""
sFilename516 = udfFileRootExt_4 ("\") ; ""
sFilename517 = udfFileRootExt_4 ("") ; ""
sFilename518 = udfFileRootExt_4 ("D:TEST.TXT") ; "TEST.TXT"
sFilename601 = udfFileRootExt_5 ("D:\TEMP\TEST.TXT") ; "TEST.TXT"
sFilename602 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\TEST.TXT") ; "TEST.TXT"
sFilename603 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\TEST.") ; "TEST."
sFilename604 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\.") ; "."
sFilename605 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\..") ; ".."
sFilename606 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\...") ; "..."
sFilename607 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\....") ; "...."
sFilename608 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\TEST") ; "TEST."
sFilename609 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP\") ; "."
sFilename610 = udfFileRootExt_5 ("\\XXX\X\TEMP TEMP") ; "TEMP TEMP."
sFilename611 = udfFileRootExt_5 ("\\XXX\X\") ; "."
sFilename612 = udfFileRootExt_5 ("\\XXX\X") ; "X."
sFilename613 = udfFileRootExt_5 ("\\XXX\") ; "."
sFilename614 = udfFileRootExt_5 ("\\XXX") ; "XXX".
sFilename615 = udfFileRootExt_5 ("\\") ; "."
sFilename616 = udfFileRootExt_5 ("\") ; "."
sFilename617 = udfFileRootExt_5 ("") ; "."
sFilename618 = udfFileRootExt_5 ("D:TEST.TXT") ; "TEST.TXT"
;------------------------------------------------------------------------------------------------------------------------------------------
:Performancetest
sMsgTitle = "Demo Performance Test"
sURL = "\\SERVER\SHARE\FOLDER\FILENAME.EXT"
iTestLoop = 1000
iMaxTests = 6
iTest=1
Display(1,sMsgTitle,"Running Test %iTest%, please wait ...")
Exclusive(@ON)
iStart = GetTickCount()
For i=1 To iTestLoop
Result = udfPathStripPath(sURL)
Next
iStop = GetTickCount()
Exclusive(@OFF)
iTicks%iTest% = iStop-iStart
iTest=2
Display(1,sMsgTitle,"Running Test %iTest%, please wait ...")
Exclusive(@ON)
iStart = GetTickCount()
For i=1 To iTestLoop
Result = udfFileRootExt_1(sURL)
Next
iStop = GetTickCount()
Exclusive(@OFF)
iTicks%iTest% = iStop-iStart
iTest=3
Display(1,sMsgTitle,"Running Test %iTest%, please wait ...")
Exclusive(@ON)
iStart = GetTickCount()
For i=1 To iTestLoop
Result = udfFileRootExt_2(sURL)
Next
iStop = GetTickCount()
Exclusive(@OFF)
iTicks%iTest% = iStop-iStart
iTest=4
Display(1,sMsgTitle,"Running Test %iTest%, please wait ...")
Exclusive(@ON)
iStart = GetTickCount()
For i=1 To iTestLoop
Result = udfFileRootExt_3(sURL)
Next
iStop = GetTickCount()
Exclusive(@OFF)
iTicks%iTest% = iStop-iStart
iTest=5
Display(1,sMsgTitle,"Running Test %iTest%, please wait ...")
Exclusive(@ON)
iStart = GetTickCount()
For i=1 To iTestLoop
Result = udfFileRootExt_4(sURL)
Next
iStop = GetTickCount()
Exclusive(@OFF)
iTicks%iTest% = iStop-iStart
iTest=6
Display(1,sMsgTitle,"Running Test %iTest%, please wait ...")
Exclusive(@ON)
iStart = GetTickCount()
For i=1 To iTestLoop
Result = udfFileRootExt_5(sURL)
Next
iStop = GetTickCount()
Exclusive(@OFF)
iTicks%iTest% = iStop-iStart
iMaxTicks = 0
For iTest=1 To iMaxTests
iMaxTicks = Max(iMaxTicks,iTicks%iTest%)
Next
For iTest=1 To iMaxTests
iPct%iTest% = 100*iTicks%iTest%/iMaxTicks
Next
sMsgText = ""
For iTest=1 To iMaxTests
sMsgText = StrCat(sMsgText,"Test ",iTest,@TAB,"Ticks = ",@TAB,iTicks%iTest%,@TAB,iPct%iTest%," %%",@CRLF)
Next
Message(sMsgTitle,sMsgText)
ClipPut(sMsgText)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
; WB Studio Run
; Test 1 Ticks = 11258 100 %
; Test 2 Ticks = 5242 46 %
; Test 3 Ticks = 4338 38 %
; Test 4 Ticks = 3942 35 % <==
; Test 5 Ticks = 3647 32 % <==
; Test 6 Ticks = 3667 32 % <==
;------------------------------------------------------------------------------------------------------------------------------------------
;*EOF*