CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2007
    Posts
    6

    Selecting random file recursively

    I'm looking for a function that would randomly select a file from a certain directory, and its subdirectories. Or, explained how to do this.

  2. #2
    Join Date
    Sep 2005
    Location
    London
    Posts
    208

    Re: Selecting random file recursively

    You can achieve your goal by using FindFirstFile Function described in the following link.
    http://msdn2.microsoft.com/en-us/library/aa364418.aspx

    I built you something to give you a roll.

    Code:
    #include <windows.h>
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    {
      WIN32_FIND_DATA files;
      HANDLE handle = FindFirstFile("./*", &files);
    
      if(handle != INVALID_HANDLE_VALUE)
      {
         do
        {
           cout <<files.cFileName<<endl;
        } while(FindNextFile(handle, &files));
      }
    
      return 0;
    }
    All you need now, is to put the result in an array and drill one using your favorite random function.

    Hope it helps
    Doron Moraz

  3. #3
    Join Date
    Oct 2007
    Posts
    6

    Re: Selecting random file recursively

    Thats what I was going to do, array, random.
    Last edited by d4rkw0lf; November 15th, 2007 at 07:51 AM.

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