Jump to content

Search the Community

Showing results for tags '_PathSplit'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 2 results

  1. 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
  2. Recently I had the need to split paths like _PathSplit outside of AutoIt. Regular expressions seemed to be the way to go and it was fun to learn a bit more about their power. I backported it to AutoIt and now use it instead of _PathSplit. This should match any combination of: servershare[$] | Drive path filename .extentionSome caveats: It only returns an array (returning strings via byref aswell seemed a tad overkill / messy) The Drive letter retains its trailing "" NOT the path (this seemed more sane as the path should be relative not anchored to the root of the drive) - Found that this was not so good for things like "C:" as the path shoud be set to "" not nothing ; #FUNCTION# ==================================================================================================================== ; Name...........: _PathSplitRegEx ; Description ...: Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing. ; Syntax.........: _PathSplitRegEx($sPath) ; Parameters ....: $sPath - The path to be split (Can contain a UNC server or drive letter) ; Return values .: Success - Returns an array with 5 elements where 0 = original path, 1 = drive, 2 = directory, 3 = filename, 4 = extension ; Author ........: Gibbo ; Modified.......: ; Remarks .......: This function does not take a command line string. It works on paths, not paths with arguments. ; This differs from _PathSplit in that the drive letter or servershare retains the "" not the path ; RegEx Built using examples from "Regular Expressions Cookbook (O’Reilly Media, 2009)" ; Related .......: _PathSplit, _PathFull, _PathMake ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _PathSplitRegEx($sPath) if $sPath="" then Return SetError(1,0,"") Local Const $rPathSplit = '^(?i)([a-z]:|[a-z0-9_.$]+[a-z0-9_.]+$?)?((?:[^/:*?"<>|rn]+)*)?([^/:*?"<>|rn.]*)((?:.[^./:*?"<>|rn]+)?)$' Local $aResult = StringRegExp($sPath, $rPathSplit, 2) Switch @error Case 0 Return $aResult Case 1 Return SetError(2, 0, "") Case 2 ;This should never happen! EndSwitch EndFunc ;==>_PathSplitRegExAnyhow, I hope someone else finds this useful Edit: @ScriptFullPath replaced with the parameter $sPath - Thanks czardas. Should have reread before posting. Edit2: Changed regex to move the trailing "" from the "root" to the begining of the path. Edit3: Edit destroyed the regex (why??) added below as well in plain code tags just in case it happens again: Local Const $rPathSplit = '^(?i)([a-z]:|[a-z0-9_.$]+[a-z0-9_.]+$?)?((?:[^/:*?"<>|rn]+)*)?([^/:*?"<>|rn.]*)((?:.[^./:*?"<>|rn]+)?)$'
×
×
  • Create New...