|
-
November 12th, 2007, 05:37 PM
#1
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.
-
November 12th, 2007, 06:16 PM
#2
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
-
November 14th, 2007, 02:29 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|