#include <WinAPIEx.au3>
;$sPath = 'C:\'
;$sPath = 'C:\34\66\34\765\3\qwerty'
$sPath = 'C:\34\66\34\765\3\qwerty\1.au3'
If StringRight($sPath, 1) == '\' Then $sPath = StringTrimRight($sPath, 1)
If StringInStr($sPath, '.') Then
$sDir = _WinAPI_PathStripPath(_WinAPI_PathRemoveFileSpec($sPath))
Else
$sDir = StringRegExpReplace($sPath, '^.*\\', '')
EndIf
MsgBox(64, 'Info-1', $sDir)
;или
$aPath = StringSplit($sPath, '\')
If StringInStr($sPath, '.') Then
$sDir = $aPath[$aPath[0] - 1]
Else
$sDir = $aPath[$aPath[0]]
EndIf
MsgBox(64, 'Info-2', $sDir)