Lb_dir

This is a discussion on Lb_dir within the Windows Programming forums, part of the Platform Specific Boards category; Hi all; Okay i have set a list box to read all the files and navigate through directorys. But all ...

  1. #1
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125

    Lb_dir

    Hi all;

    Okay i have set a list box to read all the files and navigate through directorys. But all i want to do is navigate the directories and only display *.avi files.

    When i do this
    SendMessage (FilesLST, LB_DIR, DIR,
    (LPARAM) TEXT ("*.avi")) ;

    only drives come up, so i have to use *.* and list everthing iside the dir. Any advise? thanks heaps.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  2. #2
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb You can try..

    Try:

    SendMessage(ListBox Handle,LB_DIR,(LPARAM)DDL_DIRECTORY,(WPARAM)"*.avi ");

    or:

    SendMessage(ListBox Handle,LB_DIR,(WPARAM)DDL_DIRECTORY,(LPARAM)"*.avi ");

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    18

    Arrow 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 : tak3over@yahoo.com

    //i`m so sleepy
    What would this world be without some1 to break into your comuter or crack your software !????

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    here's a snippet from a MP3 player I made a while ago...

    Code:
    	char pathname[255]={0};
    	struct _finddata_t fileinfo;
    	long findhandle;
    				GetDlgItemText(hwnd, IDC_FOLDER, pathname, 255);
    				strcat(pathname,"*.mp3");
    
    				findhandle = _findfirst(pathname,&fileinfo);
    
    				if (findhandle==-1)
    				{
    					MessageBox(NULL, "Directory Not Found", "Error", MB_OK);
    					return FALSE;
    				}
    				SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)fileinfo.name);
    				while(_findnext(findhandle,&fileinfo)==0)
    				{
    					SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)fileinfo.name);
    				}
    It's a lot better than using LB_DIR because it gives the full filename, not just the DOS version.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21