CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2008
    Posts
    70

    Questions about file system

    i have questions about file system

    the first one is how i can list all file in directory

    i tried to do this but it lists directories only not files

    Code:
    void ListFiles(TCHAR szDirectory[])
    {
    WIN32_FIND_DATA findData;
    HABDLE hfind;
    BOOL bMoreFiles=TRUE;
    hFind=FindFirstFile(szDirectory,&findData);
    
    
    if(findData.dwFileAttributes ==FILE_ATTRIBUTE_ARCHIVE)//FILE
    {
    while(bMoreFiles)
    {
    wcout<<findData.cFileName;
    bMoreFiles=FindNextFile(szDirectory,&findData);
    }
    }//if
    else if(findData.dwFileAttributes ==FILE_ATTRIBUTE_DIRECTOR)Y //directory not file
    ListFiles(findData.cFileName);//using recursion
    
    else 
    return ;
    }//ListFiles()
    the second one is
    let's say i want to show all images in directory
    how can i know the type of the file (file extension)

    thnx

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Questions about file system

    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    Mar 2008
    Posts
    70

    Re: Questions about file system

    thank you so much and i'm sorry to not to search in forums

    but what about the second question it's important to me
    Last edited by ALEXSNIPER; May 17th, 2010 at 04:04 PM.

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Questions about file system

    Well you can either set lpFileName in FindFirstFile to *.jpg or you can ignore all files but imagefiles after reviewing the result in lpFindFileData. Ignoring the wrong files is probably what you want since I guess you would like to find jpeg, bmp, tif and so on as well.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    Join Date
    Oct 2005
    Location
    Minnesota, U.S.A.
    Posts
    680

    Re: Questions about file system

    Get Rid of FILE_ATTRIBUTE_ARCHIVE and use FILE_ATTRIBUTE_NORMAL.

    -Erik

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