use this and thank me !:)
BOOL IsFileWithExt(char *file,char *ext)
{
int i=0;
char ex[5]="";
for(i=(int)strlen(file);i>0;i++)
{
if(file[i]!='.')
sprintf(ex,"%s%c",ex,file[i]);
else
break;
}
strcpy(ext,strrev(ext));
if(!strcmpi(ext,ex))
return TRUE;
else
return FALSE;
return FALSE;
}
void EnumFiles(HWND listbox,char *directory,char *ext,BOOL subdirs,BOOL showfullpath,BOOL byext,BOOL showdirs)
//listbox - handle to listbox windows
//directory - path to search in
//ext - extension (exe or *) - used only with byext=TRUE
//subdirs - look in subdirs too
//showfullpath - enter the full path in the listbox or only the file name
//byext - ignore files not matching extension
//showdirs - insert the directories in the listbox , not only files
{
HANDLE hFile;
WIN32_FIND_DATA findData;
BOOL Go=TRUE;
char file[500]="",fullpath[500]="";
strcpy(file,Directory);
if(strcmpi(ext,"*")==0)
byext=FALSE;
if(strcmpi(ext,"")==0)
byext=FALSE;
if(Directory[strlen(directory)-1]!='\\')
strcat(directory,"\\");
strcpy(file,directory);
strcat(file,"*.*");
hFile=FindFirstFile(file,&findData);
while((hFile!=INVALID_HANDLE_VALUE)&&(Go))
{
Go=FindNextFile(hFile,&findData);
strcpy(fullpath,"");
if((strcmpi(findData.cFileName,".")!=0)&&(strcmpi( findData.cFileName,"..")!=0))
{
sprintf(fullpath,"%s%s",directory,findData.cFileNa me);
if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(subdirs)
{
EnumFiles(listbox,fullpath,ext,subdirs,showfullpat h,byext,showdirs);
}
if(showdirs)
SendMessage(listbox,LB_ADDSTRING,0,(LPARAM)fullpat h);
else
SendMessage(listbox,LB_ADDSTRING,0,(LPARAM)findDat a.cFileName);
}
else
{
if(byext)
{
if(!IsFileWithExt(fullpath,ext))
continue;
}
if(showfullpath)
SendMessage(listbox,LB_ADDSTRING,0,(LPARAM)fullpat h);
else
SendMessage(listbox,LB_ADDSTRING,0,(LPARAM)findDat a.cFileName);
}
}
}
}
///if i have any mistakes it`s late and i`m sleepy ! you should see them ! be cool !
//example : EnumFiles(GetDlgItem(hWnd,IDC_FILELIST),"C:\\","ex e",FALSE,FALSE,TRUE); will list only c:\ for files with
//for any help : [email protected]
//i`m so sleepy :o