Get Path Name

S

scott

Below I have a function that returns a file name when a full file path is
passed as a parameter. So for example, "c:\temp\myfile.txt" is returned as
"myfile.txt".

How can I do the same thing, except return "c:\temp\" or the path minus the
file name?

CODE *********

Function StripIt(sWhat As String)
StripIt = Right(sWhat, Len(sWhat) - InStrRev(sWhat, "\"))
End Function
 
M

Marshall Barton

scott said:
Below I have a function that returns a file name when a full file path is
passed as a parameter. So for example, "c:\temp\myfile.txt" is returned as
"myfile.txt".

How can I do the same thing, except return "c:\temp\" or the path minus the
file name?

CODE *********

Function StripIt(sWhat As String)
StripIt = Right(sWhat, Len(sWhat) - InStrRev(sWhat, "\"))
End Function

sPath = Left(sWhat, InStrRev(sWhat, "\"))
 
R

RoyVidar

scott wrote in message said:
Below I have a function that returns a file name when a full file
path is passed as a parameter. So for example, "c:\temp\myfile.txt"
is returned as "myfile.txt".

How can I do the same thing, except return "c:\temp\" or the path
minus the file name?

CODE *********

Function StripIt(sWhat As String)
StripIt = Right(sWhat, Len(sWhat) - InStrRev(sWhat, "\"))
End Function

For some fun and flexibility, you might have a look at the methods of
the hidden WizHook object

Dim strDrive As String
Dim strDir As String
Dim strFile As String
Dim strExt As String

Const cstrFullName As String = _
"G:\MYPICTURES\123456.JPG"

With WizHook
.Key = 51488399
.SplitPath cstrFullName, strDrive, strDir, strFile, strExt
Debug.Print strDrive, strDir, strFile, strExt
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top