// include STL headers #include #include #include #include // c style system-headers #include #include #include #include int main(int argc, char *argv[]) { if (argc < 2) { std::cout << "run-dir.exe by Torben Nielsen" << std::endl; std::cout << "runs all (.exe) files in a directory, with optional args" << std::endl; std::cout << "Usage: run-dir.exe " << std::endl; std::cout << "Example: run-dir.exe c:\\update /passive /norestart" << std::endl; return 0; } DIR *directory = opendir( argv[1] ); if (directory == NULL) { std::cout << "Could not read directory " << argv[1] << " - "; std::cout << strerror(errno) << std::endl; return 1; } std::vector files; dirent *file; while ( (file = readdir(directory)) != NULL ) { std::string filename = file->d_name; if (filename.size() < 5) continue; std::string ext = filename.substr(filename.size()-4,4); if (ext == ".exe") files.push_back( filename ); } closedir(directory); std::string arguments = ""; if (argc>2) { for (int i=2;i::size_type i = 0; i < files.size(); i++) { std::string fullname = argv[1]; fullname.append("\\").append(files[i]); fullname.append(arguments); std::cout << "executing " << fullname << std::endl; int errorval = system(fullname.c_str()); if (errorval != 0) std::cerr << "Warning: " << files[i] << " returned " << errorval << std::endl; } }