tags:

views:

67

answers:

2

How to get a text file only?

Using VB 6

MY path -  C:\Documents and Settings\Arshad\My Documents\ravi.txt

I want to get ravi file name only. How to get?

Need vb 6 code Help

+1  A: 

Have a look at this: Retrieve Filename without Path or Extension.

Here's the function from the above link:

Public Function GetFileName(flname As String) As String

    'Get the filename without the path or extension.
    'Input Values:
    '   flname - path and filename of file.
    'Return Value:
    '   GetFileName - name of file without the extension.

    Dim posn As Integer, i As Integer
    Dim fName As String

    posn = 0
    'find the position of the last "\" character in filename
    For i = 1 To Len(flname)
        If (Mid(flname, i, 1) = "\") Then posn = i
    Next i

    'get filename without path
    fName = Right(flname, Len(flname) - posn)

    'get filename without extension
    posn = InStr(fName, ".")
        If posn <> 0 Then
            fName = Left(fName, posn - 1)
        End If
    GetFileName = fName
End Function

When inputting

C:\Documents and Settings\Arshad\My Documents\ravi.txt

this function returns

ravi

The function is called as such:

Dim FileName As String
FileName = GetFileName("C:\Documents and Settings\Arshad\My Documents\ravi.txt")
Bernhof
@Bernhof - I need ravi only
Gopal
I updated the post. The article I linked to in the first place, has a code snippet that does exactly that.
Bernhof
A: 

Here you go:

http://www.vbforums.com/showthread.php?t=475667

Ron Klein