I need to get a directory listing of a specific directory (like dir /b in cmd) that is in the same place as my app's exe file.
Here is what I have tried:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
BROWSEINFO BrowsingInfo;
LPITEMIDLIST ItemID;
char szDirPath[MAX_PATH];
memset(&BrowsingInfo, 0, sizeof(BROWSEINFO));
memset(szDirPath, 0, MAX_PATH);
memset(szFolderName, 0, MAX_PATH);
BrowsingInfo.hwndOwner = Application->Handle;
BrowsingInfo.lpszTitle = "Select A Folder";
BrowsingInfo.ulFlags = BIF_RETURNONLYFSDIRS;
ItemID = SHBrowseForFolder(&BrowsingInfo);
SHGetPathFromIDList(ItemID, szDirPath);
Label1->Caption = szDirPath;
}
That code gives you a path to a folder that is selected by the user.
To then get the contents of that folder, you have to enumerate the contents manually. You have a few options for that:
FindFirstFile()andFindNextFile()functions:FindFirst()andFindNext()functions (inSysUtils.hpp):IShellFolderinterface, in particular itsEnumObjects()method:BTW, C++Builder also has a
SelectDirectory()function (inFileCtrl.hpp) that wraps theSHBrowseForFolder()API for you: