Jump to content
VIP

[Help] Path Split WITH StringRegExp

Recommended Posts

Need help to make function better :) with full infomation

#include <Array.au3>
#include <File.au3>

_TEST(@ScriptFullPath)
_TEST("A:")
_TEST("A:\B.c")
_TEST("D:\E\F\")
_TEST("G:\H/../J.k/")
_TEST("M:\N\k..J.k")
_TEST("D:\E\F\..\G\G\I..J.K.M")

Func _TEST($sFilePath)
    Local $sDrive = "", $sFullPathDir = "", $sDirPath = "", $sDirName = "", $sFileName = "", $sFileNameExt = "", $sExtension = "", $sExt = ""
    Local $aPathSplit = _PathSplitByRef($sFilePath, $sDrive, $sFullPathDir, $sDirPath, $sDirName, $sFileName, $sFileNameExt, $sExtension, $sExt)

    ConsoleWrite("!Path IN     : " & $sFilePath & @CRLF)    ; C:\Windows\System32\etc\hosts.exe
    ConsoleWrite("- Driver     : " & $sDrive & @CRLF)       ; C:
    ConsoleWrite("- DirPath    : " & $sFullPathDir & @CRLF) ; C:\Windows\System32\etc\etc
    ConsoleWrite("- DirPath    : " & $sDirPath & @CRLF)     ; \Windows\System32\etc\
    ConsoleWrite("- DirName    : " & $sDirName & @CRLF)     ; etc
    ConsoleWrite("- FileName   : " & $sFileName & @CRLF)    ; hosts
    ConsoleWrite("- FileNameExt: " & $sFileNameExt & @CRLF) ; hosts.exe
    ConsoleWrite("- Extension  : " & $sExtension & @CRLF)   ; .exe
    ConsoleWrite("- Ext        : " & $sExt & @CRLF & @CRLF) ; exe

;~     ConsoleWrite("!Path IN     : " & $aPathSplit[0] & @CRLF)   ; C:\Windows\System32\etc\hosts.exe
;~     ConsoleWrite("- Driver     : " & $aPathSplit[1] & @CRLF)   ; C:
;~     ConsoleWrite("- DirPath    : " & $aPathSplit[2] & @CRLF)   ; C:\Windows\System32\etc\etc
;~     ConsoleWrite("- DirPath    : " & $aPathSplit[3] & @CRLF)   ; \Windows\System32\etc\
;~     ConsoleWrite("- DirName    : " & $aPathSplit[4] & @CRLF)   ; etc
;~     ConsoleWrite("- FileName   : " & $aPathSplit[5] & @CRLF)   ; hosts
;~     ConsoleWrite("- FileNameExt: " & $aPathSplit[6] & @CRLF)   ; hosts.exe
;~     ConsoleWrite("- Extension  : " & $aPathSplit[7] & @CRLF)   ; .exe
;~     ConsoleWrite("- Ext        : " & $aPathSplit[8] & @CRLF)   ; exe

;~  _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath)
EndFunc   ;==>_TEST

Func _PathSplitByRef($sFilePath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDirPath, ByRef $sDirName, ByRef $sFileName, ByRef $sFileNameExt, ByRef $sExtension, ByRef $sExt)
    If StringInStr($sFilePath,"..") Then $sFilePath=_PathFull($sFilePath)
    Local $aPartOfPath=StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
;~  If @error Then
        ReDim $aPartOfPath[9]
;~      $aPartOfPath[0] = $sFilePath
;~  EndIf
    $aPartOfPath[0] = $sFilePath                       ; C:\Windows\System32\etc\hosts.exe
    $sDrive = $aPartOfPath[1]                          ; C:
    $sFullPathDir = $aPartOfPath[1] & $aPartOfPath[2]  ; C:\Windows\System32\etc
    If StringLeft($aPartOfPath[2], 1) == "/" Then
        $sDirPath = StringRegExpReplace($aPartOfPath[2], "\h*[\/\\]+\h*", "\/")
    Else
        $sDirPath = StringRegExpReplace($aPartOfPath[2], "\h*[\/\\]+\h*", "\\")
    EndIf
    $aPartOfPath[2] = $sFullPathDir                 ; C:\Windows\System32\etc

    $sDirName=StringReplace($sDirPath,"\","")
    $sDirName=StringReplace($sDirPath,"/","")

    $sFileName = $aPartOfPath[3]                    ; hosts
    $aPartOfPath[5] = $sFileName                    ; hosts

    $sExtension = $aPartOfPath[4]                   ; .exe
    $aPartOfPath[7] = $sExtension                   ; .exe

    $aPartOfPath[3] = $sDirPath                     ; \Windows\System32\etc\
    $aPartOfPath[4] = $sDirName                     ; etc

    $aPartOfPath[6] = $sFileName & $sExtension      ; hosts.exe
    $sFileNameExt = $aPartOfPath[6]                 ; hosts.exe

    $sExt = StringReplace($sExtension,".","")   ; exe
    $aPartOfPath[8] = $sExt                         ; exe

    Return $aPartOfPath
EndFunc   ;==>_PathSplitByRef

 

Edited by Trong
code

Share this post


Link to post
Share on other sites

Same 

; #FUNCTION# ====================================================================================================================
; Author ........: Valik
; Modified.......: DXRW4E - Re-wrote to use a regular expression; guinness - Update syntax and structure.
; ===============================================================================================================================
Func _PathSplit($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
    If @error Then ; This error should never happen.
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    Return $aArray
EndFunc   ;==>_PathSplit

but need

10 minutes ago, Trong said:

make working and better :)

Share this post


Link to post
Share on other sites

Not sure I understand working and better when it literally does everything you're asking us to try and figure out.....

#include <Array.au3>
#include <File.au3>

Global $sDrive, $sDir, $sFileName, $sExtension

_ArrayDisplay(_PathSplit(@ScriptFullPath, $sDrive, $sDir, $sFileName, $sExtension))
_ArrayDisplay(_PathSplit("A:", $sDrive, $sDir, $sFileName, $sExtension))
_ArrayDisplay(_PathSplit("A:\B.c", $sDrive, $sDir, $sFileName, $sExtension))
_ArrayDisplay(_PathSplit("D:\E\F\", $sDrive, $sDir, $sFileName, $sExtension))
_ArrayDisplay(_PathSplit("G:\H/../J.k/", $sDrive, $sDir, $sFileName, $sExtension))
_ArrayDisplay(_PathSplit("M:\N\k..J.k", $sDrive, $sDir, $sFileName, $sExtension))
_ArrayDisplay(_PathSplit("D:\E\F\..\G\G\I..J.K.M", $sDrive, $sDir, $sFileName, $sExtension))

 

Edited by InunoTaishou

Share this post


Link to post
Share on other sites

_PathSplit()        :  $sFilePath, $sDrive, $sDir, $sFileName, $sExtension
_PathSplitNEW(): $sFilePath, $sDrive, $sFullPathDir, $sDirPath, $sDirName, $sFileName, $sFileNameExt, $sExtension, $sExt

Add: $sFullPathDir, $sDirName, $sFileNameExt, $sExt

Share this post


Link to post
Share on other sites

$sFullPathDir is [0] (Unless you mean full path without the file then it's [1] & [2])

$sDirName is [2] unless you mean the last folder the file is in. In which case you can get that using StringTrimLeft, StringRight, or StringMid

$sFileNameExt and $sExt are [4]

#include <Array.au3>
#include <File.au3>

Global $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension

_ArrayDisplay(_PathSplitEx(@ScriptFullPath, $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))
_ArrayDisplay(_PathSplitEx("A:", $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))
_ArrayDisplay(_PathSplitEx("A:\B.c", $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))
_ArrayDisplay(_PathSplitEx("D:\E\F\", $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))
_ArrayDisplay(_PathSplitEx("G:\H/../J.k/", $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))
_ArrayDisplay(_PathSplitEx("M:\N\k..J.k", $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))
_ArrayDisplay(_PathSplitEx("D:\E\F\..\G\G\I..J.K.M", $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension))

Func _PathSplitEx($sPath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDir, ByRef $sFolder, ByRef $sFileName, ByRef $sExtension)
    Local $aReturn = _PathSplit($sPath, $sDrive, $sDir, $sFileName, $sExtension)
    $sFullPathDir = $aReturn[1] & $aReturn[2]
    $sFolder = StringRight($aReturn[2], StringLen($aReturn[2]) - StringInStr($aReturn[2], "\", 0, -2))
    _ArrayInsert($aReturn, 2, $sFullPathDir)
    _ArrayInsert($aReturn, 4, $sFolder)
    Return $aReturn
EndFunc

 

Edited by InunoTaishou

Share this post


Link to post
Share on other sites

I want it better and use StringRegExp, your code too long

 

#include <Array.au3>
#include <File.au3>

_TEST("C:\Windows\System32\etc\hosts.exe")
_TEST("A:")
_TEST("A:\B.c")
_TEST("D:\E\F\")
_TEST("G:\H/../J.k/")
_TEST("M:\N\k..J.k")
_TEST("D:\E\F\..\G\G\I..J.K.M")

Func _TEST($sFilePath)
    Local $sDrive, $sDir, $sFileName, $sExtension, $sFullPathDir, $sDirName, $sFileNameExt, $sExt
    Local $aPathSplit = _PathSplitByRef($sFilePath, $sDrive, $sDir, $sFileName, $sExtension, $sFullPathDir, $sDirName, $sFileNameExt, $sExt)
    _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath)
EndFunc   ;==>_TEST

Func _PathSplitByRef($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension, ByRef $sFullPathDir, ByRef $sDirName, ByRef $sFileNameExt, ByRef $sExt)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
;~     If @error Then ; This error should never happen.
        ReDim $aArray[9]
        $aArray[0] = $sFilePath
;~     EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
        $sDirName = StringReplace(StringRight($sDrive & $sDir, StringInStr($sDrive & $sDir, "\") + 1), "/", "")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
        $sDirName = StringReplace(StringRight($sDrive & $sDir, StringInStr($sDrive & $sDir, "\") + 1), "\", "")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    $sFullPathDir = $sDrive & $sDir
    $aArray[5] = $sFullPathDir
    $aArray[6] = $sDirName
    $sFileNameExt = $sFileName & $sExtension
    $aArray[7] = $sFileNameExt
    $sExt = StringReplace($sExtension, ".", "")
    $aArray[8] = $sExt
    Return $aArray
EndFunc   ;==>_PathSplitByRef

 

Edited by Trong
...

Share this post


Link to post
Share on other sites

My code's too long...? It's 4 extra lines...

Well maybe one of the more experienced RegEx experts can help you out then. Just know that in some instances, using String* functions are actually faster than a StringRegExp call.

Share this post


Link to post
Share on other sites

Your function working too slow! UDF it's not just 4 lines!
TEST SPEED:
Start process SpitPath1....Done on: 27804.4166587552
Start process SpitPath2....Done on: 116759.591921566

#include <Array.au3>
#include <File.au3>


Local $sFileList = @TempDir & "\~FileListALL.txt"
If Not FileExists($sFileList) Then
    ConsoleWrite("Get file list....")
    Local $StartTimeGetListFile = TimerInit()
    Local $aFileList = _FileListToArrayRec(@HomeDrive&"\", "*.*", 0, 1, 1, 2)
    Local $EndTimeGetListFile = TimerDiff($StartTimeGetListFile)
    ConsoleWrite("Done on: " & $EndTimeGetListFile & @CRLF)
    ConsoleWrite("Wrting file list!")
    Local $StartTimeSaveListFile = TimerInit()
    Local $sFileContent
    For $i = 1 To $aFileList[0] - 1
        $sFileContent &= $aFileList[$i] & @CRLF
    Next
    Local $sFileOpen = FileOpen($sFileList, 2)
    FileWrite($sFileOpen, $sFileContent)
    FileClose($sFileOpen)
    Local $EndTimeSveListFile = TimerDiff($StartTimeSaveListFile)
    ConsoleWrite("Done on: " & $EndTimeSveListFile & @CRLF)
EndIf

ConsoleWrite("Start process SpitPath1....")
Local $StartTimeProcess = TimerInit()
Local $aFileList = FileReadToArray($sFileList)
For $i = 0 To UBound($aFileList) - 1
    _TEST1($aFileList[$i])
Next
Local $EndTimeProcess = TimerDiff($StartTimeProcess)
ConsoleWrite("Done on: " & $EndTimeProcess & @CRLF)

ConsoleWrite("Start process SpitPath2....")
Local $StartTimeProcess = TimerInit()
Local $aFileList = FileReadToArray($sFileList)
For $i = 0 To UBound($aFileList) - 1
    _TEST2($aFileList[$i])
Next
Local $EndTimeProcess = TimerDiff($StartTimeProcess)
ConsoleWrite("Done on: " & $EndTimeProcess & @CRLF)

Func _TEST1($sFilePath)
    Local $sDrive, $sDir, $sFileName, $sExtension, $sFullPathDir, $sDirName, $sFileNameExt, $sExt
    Local $aPathSplit = _PathSplitByRef($sFilePath, $sDrive, $sDir, $sFileName, $sExtension, $sFullPathDir, $sDirName, $sFileNameExt, $sExt)
;~  _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath)
EndFunc   ;==>_TEST1

Func _TEST2($sFilePath)
    Local $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension
    Local $aPathSplit = _PathSplitEx($sFilePath, $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension)
EndFunc   ;==>_TEST2



Local $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension
Func _PathSplitEx($sPath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDir, ByRef $sFolder, ByRef $sFileName, ByRef $sExtension)
    Local $aReturn = _PathSplit($sPath, $sDrive, $sDir, $sFileName, $sExtension)
    $sFullPathDir = $aReturn[1] & $aReturn[2]
    $sFolder = StringRight($aReturn[2], StringLen($aReturn[2]) - StringInStr($aReturn[2], "\", 0, -2))
    _ArrayInsert($aReturn, 2, $sFullPathDir)
    _ArrayInsert($aReturn, 4, $sFolder)
    Return $aReturn
EndFunc   ;==>_PathSplitEx

Func _PathSplitByRef($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension, ByRef $sFullPathDir, ByRef $sDirName, ByRef $sFileNameExt, ByRef $sExt)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
;~     If @error Then ; This error should never happen.
    ReDim $aArray[9]
    $aArray[0] = $sFilePath
;~     EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
        $sDirName = StringReplace(StringRight($sDrive & $sDir, StringInStr($sDrive & $sDir, "\") + 1), "/", "")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
        $sDirName = StringReplace(StringRight($sDrive & $sDir, StringInStr($sDrive & $sDir, "\") + 1), "\", "")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    $sFullPathDir = $sDrive & $sDir
    $aArray[5] = $sFullPathDir
    $aArray[6] = $sDirName
    $sFileNameExt = $sFileName & $sExtension
    $aArray[7] = $sFileNameExt
    $sExt = StringReplace($sExtension, ".", "")
    $aArray[8] = $sExt
    Return $aArray
EndFunc   ;==>_PathSplitByRef

 

Edited by Trong
CODE

Share this post


Link to post
Share on other sites

Slight modification makes my Ex function only a few milliseconds slower than yours (using 22,061 files to split)

Func _PathSplitEx($sPath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDir, ByRef $sFolder, ByRef $sFileName, ByRef $sExtension)
    Local $aReturn = _PathSplit($sPath, $sDrive, $sDir, $sFileName, $sExtension)
    $sFullPathDir = $aReturn[1] & $aReturn[2]
    $sFolder = StringRight($aReturn[2], StringLen($aReturn[2]) - StringInStr($aReturn[2], "\", 0, -2))
    Return StringSplit($sPath & "|" & $sDrive & "|" & $sFullPathDir & "|" & $sDir & "|" & $sFolder & "|" & $sFileName & "|" & $sExtension, "|", $STR_NOCOUNT)
EndFunc   ;==>_PathSplitEx

_ArrayInsert has a large overhead. In a real world practice it would never be noticed, since, honestly, no one is going to call _PathSplit thousands of times in a row. Creating a new string and returning the split version increases the call substantially. And, looks a hell of a lot cleaner.

Share this post


Link to post
Share on other sites

Anyway thank you for your interest and reply!

For me speed and simplicity are always given priority. I will try to learn to optimize code more.
A program does not just use a single function.
If you work with computers/VPS with low profile you will see the difference.


 

#include <Array.au3>
#include <File.au3>


Local $sFileList = @TempDir & "\~FileListALL.txt"
;~ Local $sFileList = @TempDir & "\~FileListTMPA.txt"
If Not FileExists($sFileList) Then
    ConsoleWrite("-Get file list....")
    Local $StartTimeGetListFile = TimerInit()
;~  Local $aFileList = _FileListToArrayRec(@HomeDrive & "\", "*.*", 0, 1, 1, 2)
;~  Local $aFileList = _FileListToArrayRec(@AppDataCommonDir & "\", "*.*", 0, 1, 1, 2)
    Local $EndTimeGetListFile = TimerDiff($StartTimeGetListFile)
    ConsoleWrite("Done on: " & $EndTimeGetListFile & @CRLF)
    ConsoleWrite("-Wrting file list!")
    Local $StartTimeSaveListFile = TimerInit()
    Local $sFileContent
    For $i = 1 To $aFileList[0] - 1
        $sFileContent &= $aFileList[$i] & @CRLF
    Next
    Local $sFileOpen = FileOpen($sFileList, 2)
    FileWrite($sFileOpen, $sFileContent)
    FileClose($sFileOpen)
    Local $EndTimeSveListFile = TimerDiff($StartTimeSaveListFile)
    ConsoleWrite("Done on: " & $EndTimeSveListFile & @CRLF)
EndIf

ConsoleWrite("+Read data ....")
Local $StartTimeRead = TimerInit()
Local $aFileList = FileReadToArray($sFileList)
Local $EndTimeRead = TimerDiff($StartTimeRead)
ConsoleWrite("Done on: " & $EndTimeRead & @CRLF)

ConsoleWrite("-Start process SpitPath1....")
Global $sDrive, $sDir, $sFileName, $sExtension, $sFullPathDir, $sDirName, $sFileNameExt
Local $StartTimeProcess = TimerInit()
For $i = 0 To UBound($aFileList) - 1
    _TEST1($aFileList[$i])
Next
Local $EndTimeProcess = TimerDiff($StartTimeProcess)
ConsoleWrite("Done on: " & $EndTimeProcess & @CRLF)

ConsoleWrite("-Start process SpitPath2....")
Global $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension
Local $StartTimeProcess = TimerInit()
For $i = 0 To UBound($aFileList) - 1
    _TEST2($aFileList[$i])
Next
Local $EndTimeProcess = TimerDiff($StartTimeProcess)
ConsoleWrite("Done on: " & $EndTimeProcess & @CRLF)

Func _TEST1($sFilePath)
;~  Local $aPathSplit =
    Return _PathSplitByRef($sFilePath, $sDrive, $sDir, $sFileName, $sExtension, $sFullPathDir, $sDirName, $sFileNameExt)
;~  _ArrayDisplay($aPathSplit, "_PathSplit of " & $sFilePath)
EndFunc   ;==>_TEST1

Func _TEST2($sFilePath)
;~  Local $aPathSplit =
    Return _PathSplitEx($sFilePath, $sDrive, $sFullPathDir, $sDir, $sFolder, $sFileName, $sExtension)
EndFunc   ;==>_TEST2

Func _PathSplitEx($sPath, ByRef $sDrive, ByRef $sFullPathDir, ByRef $sDir, ByRef $sFolder, ByRef $sFileName, ByRef $sExtension)
    Global $aReturn = _PathSplit($sPath, $sDrive, $sDir, $sFileName, $sExtension)
    $sFullPathDir = $aReturn[1] & $aReturn[2]
    $sFolder = StringRight($aReturn[2], StringLen($aReturn[2]) - StringInStr($aReturn[2], "\", 0, -2))
    Return StringSplit($sPath & "|" & $sDrive & "|" & $sFullPathDir & "|" & $sDir & "|" & $sFolder & "|" & $sFileName & "|" & $sExtension, "|", $STR_NOCOUNT)
EndFunc   ;==>_PathSplitEx


Func _PathSplitByRef($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension, ByRef $sFullPathDir, ByRef $sDirName, ByRef $sFileNameExt)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", $STR_REGEXPARRAYMATCH)
;~     If @error Then ; This error should never happen.
    ReDim $aArray[8]
    $aArray[0] = $sFilePath
;~     EndIf
    $sDrive = $aArray[1]
    If StringLeft($aArray[2], 1) == "/" Then
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/")
        $sDirName = StringReplace(StringRight($sDrive & $sDir, StringInStr($sDrive & $sDir, "\") + 1), "/", "")
    Else
        $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\")
        $sDirName = StringReplace(StringRight($sDrive & $sDir, StringInStr($sDrive & $sDir, "\") + 1), "\", "")
    EndIf
    $aArray[2] = $sDir
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    $sFullPathDir = $sDrive & $sDir
    $aArray[5] = $sFullPathDir
    $aArray[6] = $sDirName
    $sFileNameExt = $sFileName & $sExtension
    $aArray[7] = $sFileNameExt
    Return $aArray
EndFunc   ;==>_PathSplitByRef

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By jmp
      i am trying to get number from string using this code :
      #include <IE.au3> $oIE = _IEAttach ("Edu.corner") Local $aName = "Student name & Code:", $iaName = "0" Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.InnerText = $aName Then $iaName = $oTd.NextElementSibling.InnerText $iGet = StringRegExpReplace($iaName, "\D", "") EndIf Next MsgBox(0, "", $iGet) it was get number like 52503058
      But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

       
    • By BlueBandana
      Is there a way to output the regex matches into a file?
      I have a script to compare two files and check for regex matches.
      I want to output the matching regex of 'testexample.txt' to another file.
      #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next  
    • By jmp
      I am adding labour charge to total paid amount using : 
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData3 = _IETableWriteToArray ($oTable) Local $sitem1 = $aTableData3[5][1] Local $sitem2 = $aTableData3[5][2] Local $lcharge = "10" ;add manualy using inputbox, becuase not generating online Local $atotPric = "Payable Total Price " Local $oTds = _IETagNameGetCollection($oIE, "td") For $oTd In $oTds If $oTd.Innertext = $atotPric Then $iatotPric = $oTd.NextElementSibling.innertext MsgBox (0, "2", $iatotPric) EndIf Next $irCtotal = StringFormat("%.2f", $sitem1 + $sitem2 + $lcharge) $crTotp = StringReplace(_IEBodyReadHTML($oIE), $iatotPric, $irCtotal) _IEBodyWriteHTML ($oIE, $crTotp) But, It was also changing Total price, I want to change only Payable Total Price.

    • By nacerbaaziz
      hello sirs
      i've some questions about StringRegExpReplace i hope you can help me
       
      i tried to make a function that give me the host of the url and other give me the url with out host
      for example i've this link
      https://www.example.com/vb/result.php
      i need the first give me the
      example.com
      and the other give me 
      /vb/result.php
      i find that
      $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page)  
      but i found some problems i need your help to correct it
      first: when i get the host if the url has www i want to remove it
      second: if the url with out host did not have other things 
      i need the result to be ""
      e.g
      https://www.example.com
      the first i want it
      example.com
      and the second i want it to be ""
      i hope that you can help me
      thanks in advance
×
×
  • Create New...