Globbing in C++/C, on Windows
Link with setargv.obj
(or wsetargv.obj
) and argv[] will be globbed for you similar to how the Unix shells do it:
I can't vouch for how well it does it though.
This is very Windows-specific. I don't know how you'd write this to be cross-platform. But I've used this in Windows programs and it works well for me.
// Change to the specified working directorystring path;cout << "Enter the path to report: ";cin >> path;_chdir(path.c_str());// Get the file descriptionstring desc;cout << "Enter the file description: ";cin >> desc;// List the files in the directoryintptr_t file;_finddata_t filedata;file = _findfirst(desc.c_str(),&filedata);if (file != -1){ do { cout << filedata.name << endl; // Or put the file name in a vector here } while (_findnext(file,&filedata) == 0);}else{ cout << "No described files found" << endl;}_findclose(file);