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!

Split Function

Status
Not open for further replies.

Brycspain

IS-IT--Management
Mar 9, 2006
150
US
I'm trying to take a text file with about 45,000 entries similar to this format:

\\Servername\share\folder\folder\file.xls

The number of subfolders varies. What I need to do is get rid of everything to the left to include the last \. I was working with the split function but don't know how to get it started from the right side of the text line. It would be easy if I could start spitting from the right side and therefore split on the first instance of \. Since the number varies, can I use ubound or something similar?
Any help would be appreciated.

Sorry I didn't post any code because frankly, everything I've tried hasn't worked.

Thanks
 
So what part of \\Servername\share\folder\folder\file.xls do you want in the end?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
A starting point:
strPath = "\\Servername\share\folder\folder\file.xls"
MsgBox Mid(strPath,InStrRev(strPath,"\")+1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As for the Split function:
strPath="\\Servername\share\folder\folder\file.xls"
a=Split(strPath,"\")
MsgBox a(UBound(a))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or, of course, you can use the FileSystemObject's GetFilename method

e.g.
Code:
[blue]MsgBox Debug.Print CreateObject("Scripting.filesystemobject").GetFileName("\\Servername\share\folder\folder\file.xls")[/blue]
 
Thanks for the quick response. I'm trying to do 2 things really...I'm attaching to a folder using the getfolder method and iterating through each file in the folder.

Code:
Set objFolder = objFSO.GetFolder(strCurrentFilePath)
Set colFiles = objFolder.Files
For Each objFile In colFiles
so something
Next

this however, returns the entire path..I can't find the method that returns the file name only.

Secondly, I have a text file as I indicated on the original post that I need to strip off everything to the left of the filename itself.

\\Servername\share\folder\folder\folder\filename

I'll try the code you posted PHV.
 
Use the .Name property instead of .Path

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top