0

Hi, I have a dialog box and basically I have set it so that the user can select multiple file. When it is set to just select 1 file I can get the string for the path of the file by

AnsiString LinkPath =  (OpenDialog1->FileName);

However when I want to retrieve the names of all of the files selected by the user, the above method only provides me with the last one highlighted by the user before they press select hence I miss out on other files if there are multiple files in the selection.

I was just wondering if anyone had come across this problem before and could possibly advise how they solved it?

after a quick bit of googling I can across the below bit of code which seems to be everything I'm looking for but For some reasons I get errors with cannot convert ansistring to const char#

char buf[_MAX_PATH + 1];

    char *p = OpenDialog1->FileName + strlen(OpenDialog1->FileName) + 1;

    do
    {
      strcpy(buf, OpenDialog1->FileName);
      if (*p)   // The case of multiple file selection
      {
        strcat(buf, "\\");
        strcat(buf, p);
      }

      // Process the file
      MessageBox(buf);

      // go to next file name
      if (*p)
        p = p + strlen(p) + 1;

    } while (*p);

If anyone knows of a better way I would love to hear about it!

thank you

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Duoas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.