_PathSplit() - With parent folder.


SUBMITTED BY: Guest

DATE: May 30, 2013, 7:55 a.m.

FORMAT: Text only

SIZE: 2.3 kB

HITS: 943

  1. Func _PathSplitEx($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sParentDir, ByRef $sFileName, ByRef $sExtension)
  2. Local $aReturn[6] = [$sFilePath], $fAppended = True, $iExtension = StringInStr($sFilePath, '.', 2, -1), $iSlash = 0
  3. If StringInStr($sFilePath, '/', 2) Then
  4. $sFilePath = StringReplace($sFilePath, '/', '\') ; Replace '/' with '\'
  5. EndIf
  6. $aReturn[2] = $sFilePath
  7. $aReturn[1] = StringLeft($sFilePath, 2) ; Drive.
  8. If $aReturn[1] == '\\' Then ; UNC path.
  9. $iSlash = StringInStr($sFilePath, '\', 2, 3)
  10. If $iSlash Then
  11. $aReturn[1] = StringLeft($sFilePath, $iSlash - 1)
  12. EndIf
  13. $aReturn[2] = 'A:' & StringTrimLeft($aReturn[2], StringLen($aReturn[1]))
  14. $iExtension = StringInStr($aReturn[2], '.', 2, -1)
  15. EndIf
  16. $iSlash = StringInStr($aReturn[2], '\', 2, -1)
  17. If $iExtension Then ; If an extension exists.
  18. $aReturn[5] = StringTrimLeft($aReturn[2], $iExtension - 1) ; Extension.
  19. $aReturn[4] = StringTrimRight(StringTrimLeft($aReturn[2], $iSlash), StringLen($aReturn[5])) ; Filename.
  20. Else
  21. $fAppended = (StringRight($aReturn[2], 1) == '\') ; Check if a backslash is appendend to the end.
  22. If Not $fAppended Then ; If backslash doesn't exist (when it's a directory) then append to the end.
  23. $aReturn[2] &= '\'
  24. $iSlash = StringInStr($aReturn[2], '\', 2, -1)
  25. EndIf
  26. EndIf
  27. $aReturn[2] = StringTrimLeft(StringLeft($aReturn[2], $iSlash), 2) ; Path.
  28. $aReturn[3] = StringTrimLeft($aReturn[2], StringInStr($aReturn[2], '\', 2, -2)) ; Parent folder.
  29. $aReturn[2] = StringTrimRight($aReturn[2], StringLen($aReturn[3])) ; Remove parent folder from the path.
  30. If Not $fAppended Then
  31. $aReturn[3] = StringTrimRight($aReturn[3], 1)
  32. EndIf
  33. If $aReturn[2] == '\' Then ; If no folder is present then copy the contents of the parent folder.
  34. $aReturn[2] &= $aReturn[3]
  35. $aReturn[3] = ''
  36. EndIf
  37. $sDrive = $aReturn[1]
  38. $sDir = $aReturn[2]
  39. $sParentDir = $aReturn[3]
  40. $sFileName = $aReturn[4]
  41. $sExtension = $aReturn[5]
  42. Return $aReturn
  43. EndFunc ;==>_PathSplitEx

comments powered by Disqus