How to get the full path of a file?
-
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
-
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
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_
-
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
I have not looked at these classes but why don't you just add a handler and/or a member variable for your purpose?
-
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_
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
-
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
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_
-
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_
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
-
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
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
-
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
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
-
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
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
-
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