Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get the full path of a file?

How to get the full path of a file?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialcomgraphicsgame-dev
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CrocodileBuck
    wrote on last edited by
    #1

    Hi, i'm using the classes from Barretto VN http://www.codeproject.com/KB/tree/enumdeskclones.aspx to build a Win32ExplorerTreeView & ListView and it works very good. Now i want to load and view an (in the Listview)doubleclicked file in another view, so i need to get the full path name and extension of a file when it is double clicked in a listview for example : F:\WORKING\MISC\OpenGL C++\OGL\MilkshapeModel.cpp I think a need a shell function or something like that? Could you help me with this? Best regards Croc

    _ M D 3 Replies Last reply
    0
    • C CrocodileBuck

      Hi, i'm using the classes from Barretto VN http://www.codeproject.com/KB/tree/enumdeskclones.aspx to build a Win32ExplorerTreeView & ListView and it works very good. Now i want to load and view an (in the Listview)doubleclicked file in another view, so i need to get the full path name and extension of a file when it is double clicked in a listview for example : F:\WORKING\MISC\OpenGL C++\OGL\MilkshapeModel.cpp I think a need a shell function or something like that? Could you help me with this? Best regards Croc

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      You are not showing the full path of the file obviously, otherwise it would have been too easy to get it from there :-D , but when you get the file name intially (from whatsoever method by extracting string from the selected path or finding files from a directory) do you store the rest of the path and extension of the file in some variable. May be a vector or something? if yes, then when the user clicks on the selected file you can map the entry in the list view to that in your data structure, prepend the path to the file name and do a ShellExecute ( not very sure that you would be needing ShellExecute.)???

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      C 1 Reply Last reply
      0
      • C CrocodileBuck

        Hi, i'm using the classes from Barretto VN http://www.codeproject.com/KB/tree/enumdeskclones.aspx to build a Win32ExplorerTreeView & ListView and it works very good. Now i want to load and view an (in the Listview)doubleclicked file in another view, so i need to get the full path name and extension of a file when it is double clicked in a listview for example : F:\WORKING\MISC\OpenGL C++\OGL\MilkshapeModel.cpp I think a need a shell function or something like that? Could you help me with this? Best regards Croc

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #3

        I have not looked at these classes but why don't you just add a handler and/or a member variable for your purpose?

        1 Reply Last reply
        0
        • _ _AnsHUMAN_

          You are not showing the full path of the file obviously, otherwise it would have been too easy to get it from there :-D , but when you get the file name intially (from whatsoever method by extracting string from the selected path or finding files from a directory) do you store the rest of the path and extension of the file in some variable. May be a vector or something? if yes, then when the user clicks on the selected file you can map the entry in the list view to that in your data structure, prepend the path to the file name and do a ShellExecute ( not very sure that you would be needing ShellExecute.)???

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          C Offline
          C Offline
          CrocodileBuck
          wrote on last edited by
          #4

          Tkanks for your quick replies, perhaps you have the time to look a bit closer to the example, becuse i tried to get these information from the file for 2 days now and it wouldn't !:confused:. Perhaps you could help me with some details specified to this example ! Best regards croc

          _ 1 Reply Last reply
          0
          • C CrocodileBuck

            Tkanks for your quick replies, perhaps you have the time to look a bit closer to the example, becuse i tried to get these information from the file for 2 days now and it wouldn't !:confused:. Perhaps you could help me with some details specified to this example ! Best regards croc

            _ Offline
            _ Offline
            _AnsHUMAN_
            wrote on last edited by
            #5

            I didn't have a look at the code as of now. Did you try what I suggested?

            Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

            C 1 Reply Last reply
            0
            • _ _AnsHUMAN_

              I didn't have a look at the code as of now. Did you try what I suggested?

              Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

              C Offline
              C Offline
              CrocodileBuck
              wrote on last edited by
              #6

              Yes i tried it, but :(( Here is the code of the function, it's a lot but i hope it will help!

              /************************************************
              * Virtual Function : OnDblclk(....)
              *
              * Purpose : Called by the Framework when the user
              * double-click on a the List Control area
              *
              * Comment : if the clicked item is a folder,
              * SelectThisItem(..) function in the
              * CShellTreeView class is called to
              * expand the the Treeview after searching
              * for the passed character string
              *
              *************************************************/
              void CShellListView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
              {
              CString text;
              char szBuff[MAX_PATH];
              CString ptrPath[5];
              int i = 0;

              // User has double-clicked, get the clicked Item
              // depending on the clicked point
              LVHITTESTINFO lvhInf;
              GetCursorPos(&lvhInf.pt);
              ScreenToClient(&lvhInf.pt);
              int item = ListView\_HitTest(GetListCtrl().m\_hWnd, &lvhInf);
              if((LVHT\_ONITEMLABEL & lvhInf.flags ) || (LVHT\_ONITEMICON & lvhInf.flags))
              {
              	
              
                 LPTVITEMDATA\* lptvid = NULL;
                 lptvid = (LPTVITEMDATA\*) m\_pMalloc->Alloc (sizeof (LPTVITEMDATA));
              
                 LVITEM lvi;
                 lvi.mask = LVIF\_PARAM;
                 lvi.iItem = lvhInf.iItem;
                 ListView\_GetItem(GetListCtrl().m\_hWnd, &lvi);
                 lptvid = (LPTVITEMDATA\*)lvi.lParam;
              
                 ULONG uAttr = SFGAO\_FOLDER;
                 lptvid->lpsfParent->GetAttributesOf(1, (LPCITEMIDLIST \*) &lptvid->lpi, &uAttr);
              
                 // is the item a Folder
                 if(uAttr & SFGAO\_FOLDER)
                 {
              	   CShellClass csc;
              	   csc.GetName(lptvid->lpsfParent , lptvid->lpi , SHGDN\_NORMAL, szBuff);
              	   this->m\_pShellTreeView->SelectThisItem(szBuff);
              
              	 
              	   IShellFolder \*psfProgFiles = NULL;
              	   HRESULT hr = lptvid->lpsfParent->BindToObject(lptvid->lpi, NULL, IID\_IShellFolder, (LPVOID \*) &psfProgFiles);
              	   if(FAILED(hr))
              		   return;
              	   lptvid->lpsfParent = psfProgFiles;
              	   LVPopulateFiles(lptvid); 
              	   
              	  
              
              	   text = szBuff;
              	   ptrPath\[i\] = text;
              	  //  AfxMessageBox(szBuff);
              	   AfxMessageBox(ptrPath\[i\]);
              	   i++;
              
                 }
                 else
                 {
              
                 // display a popup-menu
              // 		ShowStdMenu(FALSE, lptvid);AfxMessageBox(szBuff);
              

              AfxMessageBox(ptrPath[0]+ptrPath[1]+ptrPath[2]+ptrPath[3]);//"It's a file not a folder"
              }
              }

              \*pResult = 0;
              

              }

              Best regards Croc

              1 Reply Last reply
              0
              • C CrocodileBuck

                Hi, i'm using the classes from Barretto VN http://www.codeproject.com/KB/tree/enumdeskclones.aspx to build a Win32ExplorerTreeView & ListView and it works very good. Now i want to load and view an (in the Listview)doubleclicked file in another view, so i need to get the full path name and extension of a file when it is double clicked in a listview for example : F:\WORKING\MISC\OpenGL C++\OGL\MilkshapeModel.cpp I think a need a shell function or something like that? Could you help me with this? Best regards Croc

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                CrocodileBuck wrote:

                I think a need a shell function or something like that?

                Sounds like SHGetPathFromIDList().

                "Love people and use things, not love things and use people." - Unknown

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                C 1 Reply Last reply
                0
                • D David Crow

                  CrocodileBuck wrote:

                  I think a need a shell function or something like that?

                  Sounds like SHGetPathFromIDList().

                  "Love people and use things, not love things and use people." - Unknown

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  C Offline
                  C Offline
                  CrocodileBuck
                  wrote on last edited by
                  #8

                  Hi Mr.Crow, yes i tried it with this function, but i didn't manage to get the file path, name and extension. Could you perhaps explain me how to use this function in the right way? Best regards Croc

                  D H 2 Replies Last reply
                  0
                  • C CrocodileBuck

                    Hi Mr.Crow, yes i tried it with this function, but i didn't manage to get the file path, name and extension. Could you perhaps explain me how to use this function in the right way? Best regards Croc

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Assuming you have a valid IDL pointer:

                    LPITEMIDLIST idl;
                    TCHAR szPath[MAX_PATH];
                    SHGetPathFromIDList(idl, szPath);

                    "Love people and use things, not love things and use people." - Unknown

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    1 Reply Last reply
                    0
                    • C CrocodileBuck

                      Hi Mr.Crow, yes i tried it with this function, but i didn't manage to get the file path, name and extension. Could you perhaps explain me how to use this function in the right way? Best regards Croc

                      H Offline
                      H Offline
                      Hamid Taebi
                      wrote on last edited by
                      #10

                      CrocodileBuck wrote:

                      how to use this function

                      See here[^].

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups