Search the Community
Showing results for tags '_splitpath'.
-
Hello, i just found the dll function _splitpath(), testet it and made a faster _PathSplit() function with the same results as the original. #include <File.au3> ;~ Global $sFile = "C:\Program Files/Another Dir\AutoIt3\AutoIt3.chm" ;~ Global $sFile = @ScriptFullPath ;~ Global $sFile = "\\127.0.0.1/SharedDocs/foo.txt" Global $sFile = "\\127.0.0.1/SharedDocs\ggg/foo.txt" Global $szDrive, $szDir, $szFName, $szExt Global $iStart, $iLoop = 10000 ConsoleWrite("_PathSplit" & @LF) $iStart = TimerInit() For $i = 1 To $iLoop _PathSplit($sFile, $szDrive, $szDir, $szFName, $szExt) Next ConsoleWrite(TimerDiff($iStart) & @LF) ConsoleWrite($szDrive & @LF) ConsoleWrite($szDir & @LF) ConsoleWrite($szFName & @LF) ConsoleWrite($szExt & @LF) ;~ MsgBox(48, $sFile, $szDrive & @LF & $szDir & @LF & $szFName & @LF & $szExt) ConsoleWrite(@LF) $szDrive = "" $szDir = "" $szFName = "" $szExt = "" ConsoleWrite("_PathSplit2" & @LF) $iStart = TimerInit() For $i = 1 To $iLoop _PathSplit2($sFile, $szDrive, $szDir, $szFName, $szExt) Next ConsoleWrite(TimerDiff($iStart) & @LF) ConsoleWrite($szDrive & @LF) ConsoleWrite($szDir & @LF) ConsoleWrite($szFName & @LF) ConsoleWrite($szExt & @LF) ;~ MsgBox(48, $sFile, $szDrive & @LF & $szDir & @LF & $szFName & @LF & $szExt) Func _PathSplit2($szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt) Local $sTemp, $pos, $pos2 Local $aRet = DllCall("MSVCRT.DLL", "none:cdecl", "_wsplitpath", "wstr", $szPath, "wstr", "", "wstr", "", "wstr", "", "wstr", "") If $aRet[2] = "" Then ; UNC path $sTemp = StringTrimLeft($aRet[3], 2) $pos = StringInStr($sTemp, "\") $pos2 = StringInStr($sTemp, "/") If $pos = 0 And $pos2 = 0 Then $szDrive = "" $szDir = $aRet[3] Else If $pos <> 0 And $pos < $pos2 Then $szDrive = StringLeft($aRet[3], $pos + 1) $szDir = StringTrimLeft($aRet[3], $pos + 1) Else $szDrive = StringLeft($aRet[3], $pos2 + 1) $szDir = StringTrimLeft($aRet[3], $pos2 + 1) EndIf EndIf Else $szDrive = $aRet[2] $szDir = $aRet[3] EndIf $szFName = $aRet[4] $szExt = $aRet[5] EndFunc