Open Files

Discussion in 'AutoCAD' started by HJohn, Apr 28, 2004.

  1. HJohn

    HJohn Guest

    The openfiles API function returns (multiselect) the path plus the file names with nullcharacter in between. However, if only one file is selected, it returns the path and the file name together in one single line (full path). What would be the easiest way of removing the path and the name? I have done something but it seams to me that there must be a cleaner way of doing this. Has anyone done something similar. Help would be greatly appreciated.
     
    HJohn, Apr 28, 2004
    #1
  2. HJohn

    Wayne Craig Guest

    Here is some "air code" that might get you shoved in the right direction:

    Dim strReturn as string 'What is returned from the Common Dialog API call
    Dim strFileArray() as string ' An array to hold the file names returned
    'Check to see if we were returned an empty string first
    If strReturn = "" then
    'Handle the condition with Exit Function or whatever is appropriate
    End IF
    'Split the return string into an array using the null string as the
    delimiter
    strFileArray=Split(strReturn, Chr(0), -1, vbTextCompare)

    'See if we were returned a single string or an array
    If Ubound(strFileArray) = -1 then
    'We have a single file returned
    End If

    I can't remember off the top of my head the exact structure of the return
    string from the API call (i.e. how the path is returned), but you should be
    able to take it from here. good luck.

    Wayne


    names with nullcharacter in between. However, if only one file is selected,
    it returns the path and the file name together in one single line (full
    path). What would be the easiest way of removing the path and the name? I
    have done something but it seams to me that there must be a cleaner way of
    doing this. Has anyone done something similar. Help would be greatly
    appreciated.
     
    Wayne Craig, Apr 29, 2004
    #2
  3. HJohn

    HJohn Guest

    Thank you Wayne for your push, but it is when only one file is selected that I am having problems. An example of a one file will be P:\Engineering Projects\Parkings\2004\1856-Parking\Columns\CL200.dwg. I go through the string and find the last \ before the file name and then split the string into path and file name. I hoped there was a one single step method of finding the last \ before the file name, instead of checking every character. Thank you again.
     
    HJohn, Apr 29, 2004
    #3
  4. Hi,

    In VB 6 based versions you can use SPLIT

    eg
    dim vString as variant
    vString = Split (Filespec,"\")
    Filename = Ubound (vString)

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    names with nullcharacter in between. However, if only one file is selected,
    it returns the path and the file name together in one single line (full
    path). What would be the easiest way of removing the path and the name? I
    have done something but it seams to me that there must be a cleaner way of
    doing this. Has anyone done something similar. Help would be greatly
    appreciated.
     
    Laurie Comerford, Apr 29, 2004
    #4
  5. HJohn

    HJohn Guest

    Great!, I used the split function with the multiple files, but I didn't see it with the single file. Two steps its all it takes, clean and beautiful. Thanks a lot.
     
    HJohn, Apr 30, 2004
    #5
  6. Hi,

    Gosh! You've given me an ego trip.

    To simplify this further I wondered if
    Filename = Split(FileSpec,"\")(Ubound(Split(FileSpec,"\")))
    would work.

    You may care to try this little bit of code

    Debug.Print Split("A,B,C", ",")(UBound(Split("A,B,C", ",")))


    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au


    see it with the single file. Two steps its all it takes, clean and
    beautiful. Thanks a lot.
     
    Laurie Comerford, May 1, 2004
    #6
  7. HJohn

    HJohn Guest

    Yes, it works. Here is a snippet of the code
    FileArr(0) = left(str, InStr(1, str, (Split(str, "\", -1, vbTextCompare)(UBound(Split(str, "\", -1, vbTextCompare))))) - 1)
    FileArr(1) = Split(str, "\", -1, vbTextCompare)(UBound(Split(str, "\", -1, vbTextCompare)))

    In my program I created the array first and the separated the path and the name.
     
    HJohn, May 3, 2004
    #7
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 (here). After that, you can post your question and our members will help you out.