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.
Printable View
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.
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.
All you need now, is to put the result in an array and drill one using your favorite random function.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;
}
Hope it helps
Doron Moraz
Thats what I was going to do, array, random.