rootx Posted August 20, 2017 Posted August 20, 2017 (edited) Hi I have a folder like C:\route\luglio\40.714224,-73.961452 I would like to rename the last folder, so i built this method, that works, i would like to know if you have other options. Thx $path = "C:\route\luglio\40.714224,-73.961452" $slash = StringReplace($path,"\","\") $Cslash = @extended $extracted = StringLeft($path, StringInStr($path,"\",0,$Cslash)) ConsoleWrite($extracted) $delim = "\" $Left = StringLeft($path,StringInStr($path, $delim,0,$Cslash)) $Right = StringMid($path,StringInStr($path, $delim,0,$Cslash) + StringLen($delim)) ConsoleWrite($Left&" "&$Right) Edited August 20, 2017 by rootx
Danp2 Posted August 20, 2017 Posted August 20, 2017 This revision gives the same results -- $path = "C:\route\luglio\40.714224,-73.961452" $delim = "\" $pos = StringInStr($path, $delim, 0, -1) $Left = StringLeft($path, $pos) $Right = StringMid($path, $pos + 1) ConsoleWrite($Left&" "&$Right & @CRLF) P.S. What didn't work for you with _pathsplit? Latest Webdriver UDF Release Webdriver Wiki FAQs
Trong Posted August 20, 2017 Posted August 20, 2017 Maybe : May be helpful for you: expandcollapse popupLocal $sDrive, $sDir, $sFileName, $sExtension, $sDirPath, $sParentDirName, $sFileNameExt Local $sFilePath = "C:\route\luglio\40.714224,-73.961452" Local $aPathSplit = _SplitPathRef($sFilePath, $sDrive, $sDir, $sFileName, $sExtension, $sDirPath, $sParentDirName, $sFileNameExt) ConsoleWrite("+ Parent Dir Name: " & _SplitPath($sFilePath, 6) & @CRLF& @CRLF) ConsoleWrite("!Path IN : " & $sFilePath & @CRLF) ; C:\Windows\System32\etc\hosts.exe ConsoleWrite("- Driver : " & $sDrive & @CRLF) ; C: ConsoleWrite("- Dir : " & $sDir & @CRLF) ; \Windows\System32\etc\ ConsoleWrite("- FileName : " & $sFileName & @CRLF) ; hosts ConsoleWrite("- Extension : " & $sExtension & @CRLF) ; .exe ConsoleWrite("- DirPath : " & $sDirPath & @CRLF) ; C:\Windows\System32\etc\etc ConsoleWrite("- ParentDirName: " & $sParentDirName & @CRLF) ; etc ConsoleWrite("- FileNameExt : " & $sFileNameExt & @CRLF & @CRLF) ; hosts.exe ; * -----:| Func _SplitPath($sFilePath, $rType = 0) Local $sDrive, $sDir, $sFileName, $sExtension, $sDirPath, $sParentDirName, $sFileNameExt Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) ;~ If @error Then ; This error should never happen. ReDim $aArray[9] $aArray[0] = $sFilePath $sDrive = $aArray[1] ;~ EndIf 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] $sParentDirName = StringRegExpReplace($sFilePath, '\\[^\\]*$', '') $sParentDirName = StringRegExpReplace($sParentDirName, '.*\\', '') $aArray[5] = $sParentDirName $sFileNameExt = $sFileName & $sExtension $aArray[6] = $sFileNameExt $sDirPath = $sDrive & $sDir $aArray[7] = $sDirPath If $rType = 1 Then Return $sDrive If $rType = 2 Then Return $sDir If $rType = 3 Then Return $sFileName If $rType = 4 Then Return $sExtension If $rType = 5 Then Return $sDirPath If $rType = 6 Then Return $sParentDirName If $rType = 7 Then Return $sFileNameExt Return $aArray EndFunc ;==>_SplitPath ; * -----:| Dao Van Trong - TRONG.WIN Func _SplitPathRef($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension, ByRef $sDirPath, ByRef $sParentDirName, ByRef $sFileNameExt) Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) ;~ If @error Then ; This error should never happen. ReDim $aArray[9] $aArray[0] = $sFilePath $sDrive = $aArray[1] ;~ EndIf 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] $sParentDirName = StringRegExpReplace($sFilePath, '\\[^\\]*$', '') $sParentDirName = StringRegExpReplace($sParentDirName, '.*\\', '') $aArray[5] = $sParentDirName $sFileNameExt = $sFileName & $sExtension $aArray[6] = $sFileNameExt $sDirPath = $sDrive & $sDir $aArray[7] = $sDirPath Return $aArray EndFunc ;==>_SplitPathRef ; * -----:| Dao Van Trong - TRONG.WIN rootx 1 Regards,
rootx Posted August 20, 2017 Author Posted August 20, 2017 P.S. What didn't work for you with _pathsplit? I meant a similar function, _pathsplit work as well but not to resolve my question.
mikell Posted August 20, 2017 Posted August 20, 2017 Did you mean something like this ? $path = "C:\route\luglio\40.714224,-73.961452" $test = "test---" Msgbox(0,"", StringRegExpReplace($path, '.+\\\K(?=[^\\]+$)', $test) ) Trong 1
iamtheky Posted August 20, 2017 Posted August 20, 2017 I Rube-Goldberged your solution $path = "C:\route\luglio\40.714224,-73.961452" $test = "test---" Msgbox(0,"", stringreverse(StringRegExpReplace(stringreverse($path), '\\' , stringreverse($test) & '\\' ,1))) Trong 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jguinch Posted August 21, 2017 Posted August 21, 2017 Also with _StringInsert : #Include <String.au3> $path = "C:\route\luglio\40.714224,-73.961452" $test = "test---" MsgBox(0, "", _StringInsert($path, $test, StringInStr($path, "\", 0, -1) )) ; MsgBox(0, "", StringRegExpReplace($path, ".+\\\K", $test) ) rootx and Trong 2 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Skysnake Posted August 21, 2017 Posted August 21, 2017 ; detemine the actual local folder ;ConsoleWrite("@ScriptDir " & @ScriptDir & @CRLF) Local $path = StringSplit(@ScriptDir, "\") ;_ArrayDisplay($path) Local $lastfoldercount = UBound($path, 1) - 1 ;ConsoleWrite("$lastfoldercount " & $lastfoldercount & @CRLF) Local $lastfolder = $path[$lastfoldercount] ;ConsoleWrite("$lastfolder " & $lastfolder & @CRLF) Trong 1 Skysnake Why is the snake in the sky?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now