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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim Help

Status
Not open for further replies.

anon1971

Programmer
Aug 9, 2008
88
US
I am having a melt down today can anyone tell me how to trim off the file path so that the file path is as indecated below:


Here is the code
FilePath = getLastTIF("\\192.168.0.11\letters\")

After it trims I need the result to be
mytiffile001.tif

Any help? The above code works great except when the filpath is saved it saves the entire path and I just need the file it self saved
 
I got it sence the path is always the same number of charcters the below works.

Left$(FilePath, 24)

thanks

 
Maybe something like this:

Code:
Option Explicit
Dim FilePath As String
Dim xArray As Variant

Sub SplitStr()
FilePath = "\\192.168.0.11\letters\mytiffile001.tif"
xArray = Split(FilePath, "\", -1)
end sub

Results are:
xAray(0) = ""
xAray(1) = ""
xAray(2) = "192.168.0.11"
xAray(3) = "Letters"
xAray(4) = "mytiffile001.tif"

Of course the number of array elements depends on the number of path elements.

If the 3rd paramater of the split function is -1 then all elements are returned

refer to help on the split function for complete use

 




Code:
sub test()
  msgbox FilePath("\\192.168.0.11\letters\mytiffile001.tif")
end sub

Function MyFile(FilePath as string)
  MyFile = Split(FilePath, "\")(ubound(Split(FilePath, "\"))
end sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Dim FilePath As String
FilePath = "\\192.168.0.11\letters\mytiffile001.tif"
MsgBox Mid$(FilePath, InStrRev(FilePath, "\") + 1)
 
Another way:
DirPath = "\\192.168.0.11\letters\"
FilePath = Replace(getLastTIF(DirPath), DirPath, "")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
And a FileSystemObject solution:

MsgBox CreateObject("scripting.filesystemobject").GetBaseName("\\192.168.0.11\letters\mytiffile001.tif")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top