Results 1 to 8 of 8

Thread: How can I get the shorten name of a file ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Location
    Bangladesh
    Posts
    19

    Post

    Hey Guys !
    Is thr any1 who can help me in this problem ? I need a code

    that will extract the shortenfilenam (only the filename)

    from a total string passed by the commondialog ?

    emranHASAN
    emranHASAN

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715

  3. #3
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    How Notepad does it

    This is the code used to get the effect that is used by Notepad. It might help.

    Code:
            frmMain.Caption = "" & CommonDialog1.FileTitle & " - Notepad"
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        CommonDialog1.InitDir = "C:\"          'set dir path
        CommonDialog1.CancelError = True               'used in cancel code
        CommonDialog1.Filter = "All files(*.*)|*.*"    'filter for all files
        CommonDialog1.ShowOpen                         'show files
        
        MsgBox CommonDialog1.FileTitle
        
        'if you don't want the extension
        Dim myLen As Integer
        myLen = Len(CommonDialog1.FileTitle)
        MsgBox Left(CommonDialog1.FileTitle, myLen - 4)
        
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Thats basicly the same as what i have just said
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715

    <!>

    Originally posted by HeSaidJoe
    Code:
    MsgBox Left(CommonDialog1.FileTitle, myLen - 4)
    This will only work if the length of the extension is 3 chars. It will not work with .jpeg or .html files.

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Electroman:
    How Notepad does it
    This is the code used to get the effect that is used by Notepad. It might help.

    I was merely pointing out that it is not specific to notepad and giving the commondialog code to do so.

    Oetje:
    Will put a fix for that in a moment.



    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'Corrected Version
    
    Option Explicit
    
    Private Sub Command1_Click()
        CommonDialog1.InitDir = "C:\"          'set dir path
        CommonDialog1.CancelError = True               'used in cancel code
        CommonDialog1.Filter = "All files(*.*)|*.*"    'filter for all files
        CommonDialog1.ShowOpen                         'show files
        
        MsgBox CommonDialog1.FileTitle
        
        Dim SearchString, SearchChar, MyPos
        SearchString = CommonDialog1.FileTitle ' String to search in.
        SearchChar = "."   ' Search for "."
    
        MyPos = InStr(1, SearchString, SearchChar, 1)
    
    'if found MyPos will be > 0
        If MyPos > 0 Then
             MsgBox Left(CommonDialog1.FileTitle, MyPos - 1)
         End If
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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