CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2000
    Location
    Ottawa, Ontario
    Posts
    356

    Getting filename path and extension

    I was wondering if anyone knows of a class or function that will spilt a filepath like "C:\TEMP\myfile.doc" into the 3 parts
    path = C:\TEMP\
    File = myfile
    extension = doc
    ???
    I know if can be done with the FSO but it's a waste to include that just for this. And I want to handle files with no extension or with 2 "."'s in the name so using string functions like instr is not reliable.

    Jean-Guy


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Getting filename path and extension

    You can use split function

    dim line() as string
    dim iIndex as integer

    line=split(path,"\")

    This will split the line at the backslash and put each element in the line() array.

    then to find the path ( without file name)

    For iIndex = LBound(line) To UBound(line)-1'except the last element which is the file name
    PATH = path & line(iIndex) & "\"
    Next

    the same way you can find the file name
    FileName=split(line(UBound(line)),".")

    something like that . I did not try it but that will give you an idea

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured