//This Scans a given Directory, puts all files into the Dir_Entries Array
//It calls the Direntry::SetExt function to set the files EXT and whether its a folder or not
//At end it sets the current Directory to the Directory just Scanned
int TSidebar::scandir(char *dirname) {
DIR *dir;
struct dirent *ent;
SHFILEINFO info;
String FilePath;
int ct = 0;
DWORD dwType;
if ((dir = opendir(dirname)) == NULL) //FAILED TO OPEN DIRECTORY
{
MessageDlg("Could not open Dir!",mtError,TMsgDlgButtons() << mbOK,0);
MessageDlg(dirname,mtError,TMsgDlgButtons() << mbOK,0);
return 0;
}
rewinddir(dir);
Dir_No_Entries = 0; // RESET ENTRY NUMBER
//Clear Directory List
while (ct < 200) {
Dir_Entries[ct].Name = "";
Dir_Entries[ct].ext = "";
Dir_Entries[ct].isfolder = false;
ct++;
}
while ((ent = readdir(dir)) != NULL){
if (Dir_No_Entries < 200) {
FilePath = dirname;
FilePath = FilePath + ent->d_name;
dwType = GetFileAttributes(FilePath.c_str());
if (dwType & FILE_ATTRIBUTE_HIDDEN) { }
else {
Dir_Entries[Dir_No_Entries].Name = ent->d_name; //Place name in Array
Dir_Entries[Dir_No_Entries].SetExt(Dir_Entries[Dir_No_Entries].Name); //Put Extension and see if folder.
DWORD ImageHandle = SHGetFileInfo(FilePath.c_str(),
0,
&info,
sizeof(info),
SHGFI_ICON |
SHGFI_SHELLICONSIZE | SHGFI_SMALLICON |
SHGFI_SYSICONINDEX);
if (ImageHandle != 0)
{
ImageList1->Handle = ImageHandle;
ImageList1->ShareImages = true;
}
Dir_Entries[Dir_No_Entries].IconIndex = info.iIcon;
Dir_No_Entries++; //Increment array pointer
}
}
}
if (closedir(dir) != 0)
MessageDlg("Could not close Dir!",mtError,TMsgDlgButtons() << mbOK,0); //Could not close??
strcpy(Cur_Dir,dirname);
return 1;
}