Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

X characters from the right

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
GB
Hi,

I have a path which I need to trim down so that I have the last folder of it. The string I have is

c:\windows\system32\copyfolder.

I need to use \copyfolder as a variable elsewhere. I have looked at various functions but can seem to find anything which wors including Right, Left and Trim. I guess from the right to the first "\" and set as a variable. Here is my code so far:


sub DeleteWebConfigb4Copy (backupdir, arrmem)
arrmem
path = backupdir & "\" & "scripts"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(path)
Set colFiles = objFolder.Files
For Each objFile in colFiles



if instr (objfile,"web.config") then
objfile.delete
wscript.echo "gone"

end if
next
end sub

Backupdir when passed to the Sub is "c:\copy and arrmem is c:\windows\system32\copyfolder and its arrmem which needs to be chopped up and added to backupdir.

Would I use Instr ?

Thanks
 
Code:
Dim s, n, x
s = "c:\windows\system32\copyfolder"
n = [COLOR=blue]InStrRev[/color](s, "\")
x = Mid(s, n)
wscript.echo s
wscript.echo n
wscript.echo x
 
Also, the fso method .GetBaseName accomplishes the same

Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = "c:\windows\system32\copyfolder"
msgbox objFSO.GetBaseName(strPath)

output:
copyFolder

-Geates

Note: favorite vbs reference site

"I hope I can feel and see the change - stop the bleed inside a feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top