CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 1999
    Posts
    13

    Get all file from a directory



    Hi


    Is it possible to Get a list of files from one directory ?

    Like this function "DlgDirList()", But we wnat to Get a list of file in other control (our control), not in ListBox

    "DlgDirList ( D->m_hWnd, path, IDC_LIST, 0, DDL_READWRITE ) ;"


    Thanks



  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Get all file from a directory



    You can try the functions _findfirst, _findnext

  3. #3
    Join Date
    Apr 1999
    Posts
    13

    Re: Get all file from a directory



    What I try to do now; (findfirst)


    How to specify for this function a directory for search ?



  4. #4
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Get all file from a directory



    You can check the attrib field of the _finddata_t structure for the value _A_SUBDIR .

    See for more info in MSDN : _find, _wfind functions.

  5. #5
    Join Date
    Apr 1999
    Posts
    13

    Re: Get all file from a directory



    There aren't _A_SUBDIR value in this struct

    struct _finddata_t {

    unsigned attrib;

    time_t time_create; /* -1 for FAT file systems */

    time_t time_access; /* -1 for FAT file systems */

    time_t time_write;

    _fsize_t size;

    char name[260];

    };


    Thanks

  6. #6
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Get all file from a directory



    You have to use the attrib-member.

    Example which displays all subdirs of the current directory

    struct _finddata_t c_file;

    long hFile;

    if ( (hFile = _findfirst("*.*", &c_file)) == -1L )

    {

    printf("No files found!\n"

    }

    else

    {

    if ( c_file.attrib & _A_SUBDIR )

    printf("Subdir found : %s\n", c_file.name);

    while ( _findnext(hFile, &c_file) == 0 )

    {

    if ( c_file.attrib & _A_SUBDIR )

    printf("Subdir found : %s\n", c_file.name);

    }

    _findclose(hFile);

    }


    Hope this helps.

  7. #7
    Join Date
    Apr 1999
    Posts
    13

    Re: Get all file from a directory



    Sory, Is not I I want to do

    I mean I want to a same search (findfirst) in different directory

    Like c:\windows and C:\toto. I have to change a Directory for that OR specify a directory in findfirst function

    How can I do that ?


    Thanks



  8. #8
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Get all file from a directory



    You can specify another directory in the _findfirst function.


    example :


    struct _finddata_t c_file;

    long hFile = _findfirst("c:\\winnt\\*.dll", &c_file);

    ...

    _findclose(hFile);



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured