CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    119

    Multi-select file dialog

    OK I'm having a strange problem with a CFile dialog which allows multiple selections. It's an open dialog. And when the user selects multiple files I use this code to enumerate the files and add their paths to a list control...

    Code:
    POSITION pos = openDlg.GetStartPosition();
    while(pos)
    {
    	CString	pathName = openDlg.GetNextPathName(pos);
    	m_cSourceFiles.AddString(pathName);
    }
    the weird part is that when I select multiple files from the root of a drive the path will have two slashes in front of the file name like so...

    F:\\Test.txt

    If I select a file from a sub directory it works fine.

    I know I can do a simple find and replace to fix it, but why is it doing this in the first place? Is this a bug in the CFileDialog code? Or something I'm doing wrong. Can anyone else able to reproduce this?

    Thanks,
    Dan

    P.S. If it matters I'm using VS2005

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Multi-select file dialog

    Quote Originally Posted by Dan203 View Post
    ...
    P.S. If it matters I'm using VS2005
    It would be more interesting which OS (Windows) version are you using?

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Multi-select file dialog

    Yes, I get that too in Windows 7, but I don't know why it is like that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Multi-select file dialog

    pathName.Replace("\\\\", "\\");

    the problem with that is that it'll also replace the double backslash at the start of an UNC filename. So it needs to be a bit more than just that.

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Multi-select file dialog

    In previous versions of Windows, using those double slashes with other Win32 API functions was not a problem. However, in Windows 7, using double slashes with certain functions will not work, so you will have to normalize your path somehow to get rid of those double slashes, except of course the double slash at the beginning of UNC names like OReubens mentioned.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  6. #6
    Join Date
    Mar 2004
    Posts
    119

    Re: Multi-select file dialog

    My machine is Win7 but I had some customers complain about this happening in XP as well.

    I used...

    pathName.Replace(":\\\\", ":\\");

    to fix it, that way it'll only get drive paths and not UNC paths. I'm just glad to hear this is a universal problem and not something weird with my app.

    Dan

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