Results 1 to 3 of 3

Thread: Filename truncation

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    I am opening a file, but I would only like to see the filename itself, not the whole path to the image. I've been trying to figure this out for some time, but I finally decided to give up and come to you guys.

    Thanks in advance,
    MidgetsBro
    <removed by admin>

  2. #2
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278
    Maybe this helps:

    Code:
    Private Sub Form_Load()
    
    Dim FullFile, Filename, Temp As String
    Dim I As Integer
    
    FullFile = "c:\MyMap\MySubMap\MyFile.txt"
    For I = 0 To Len(FullFile)
        Temp = Mid(FullFile, Len(FullFile) - I, 1) 'select 1 character
        If Temp = "\" Then 'if the caracter is a slash
            Filename = Mid(FullFile, Len(FullFile) - I + 1, I) 'delete the piece of path witch comes before the slash and the slash itself
            Exit For
        End If
    Next I
    
    MsgBox FullFile & " was turned into " & Filename :)
    
    End Sub
    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  3. #3
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Run the code below to see a few of the features of using the FileSystemObject on a file path.

    Code:
    Private Sub Command1_Click()
        Dim oFSO As Object
        Dim filePath As String
        Set oFSO = CreateObject("Scripting.FileSystemObject")
    
        filePath = "c:\folder1\folder2\textfile.txt"
        
        MsgBox "Filename (no extension) = " & oFSO.getbasename(filePath) & vbCrLf & _
               "Filename with extension = " & oFSO.getfilename(filePath) & vbCrLf & _
               "Extension = " & oFSO.getextensionname(filePath) & vbCrLf & _
               "Drive = " & oFSO.getdrivename(filePath)
    End Sub
    I hope this helps you out.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width