d4rkw0lf
November 12th, 2007, 04:37 PM
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.
|
Click to See Complete Forum and Search --> : Selecting random file recursively d4rkw0lf November 12th, 2007, 04:37 PM 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. Doron Moraz November 12th, 2007, 05:16 PM 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. #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 d4rkw0lf November 14th, 2007, 01:29 AM Thats what I was going to do, array, random. codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |