dan29
asked on
vbscript - manipulating strings
Hello I'm writing a script and I've appeard to come to a screeching halt. What I am trying to do is get the path to a folder (which I can do without an issue) then add a character in front of the last folder in the path. So let's say my original folder path is this:
\\(servername)\SMSPackages \test
I need to append the characters zzz_ in front of the last folder in the path, like so
\\(servername)\SMSPackages \zzz_test
I've tried doing this by starting left to right, but all of the characters on the left get removed, so I just end up with the path: zzz_test. And I didn't want to start from the right to left, because this script should work for any folder in this path, and they all have different names so they could have a different amount of characters. I'm sure there has to be a way to do this I just can't seem to figure this out. Thanks.
-Dan
\\(servername)\SMSPackages
I need to append the characters zzz_ in front of the last folder in the path, like so
\\(servername)\SMSPackages
I've tried doing this by starting left to right, but all of the characters on the left get removed, so I just end up with the path: zzz_test. And I didn't want to start from the right to left, because this script should work for any folder in this path, and they all have different names so they could have a different amount of characters. I'm sure there has to be a way to do this I just can't seem to figure this out. Thanks.
-Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help guys. Shift-3 yours worked so I will use yours as the solution. But thank you Rob for the alternative solution and I will try this as well.
strPath = "\\hostname\SMSPackages\te
strCharacters = "zzz_"
' Get the path without the last bit
strPathOnly = Left(strPath, InStrRev(strPath, "\"))
' Then get the last bit
strFolder = Mid(strPath, InStrRev(strPath, "\") + 1)
' Put it all together
strFullPath = strPathOnly & strCharacters & strFolder
Of course, that can all be placed on one messy line:
strPath = "\\hostname\SMSPackages\te
strCharacters = "zzz_"
strFullPath = Left(strPath, InStrRev(strPath, "\")) & strCharacters & Mid(strPath, InStrRev(strPath, "\") + 1)
Regards,
Rob.