1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <ClanLib/core.h>
#include <ClanLib/application.h>
class DirectoryTest : public CL_ClanApplication
{
public:
// This function returns the name of your game
virtual char *get_title()
{
return "Directory Test";
}
virtual int main(int argc, char **argv)
{
// Create a console window for text-output if not available
CL_ConsoleWindow console("Console");
console.redirect_stdio();
std::string pathname;
std::string pattern;
if (argc == 1)
{
pathname = "";
}
else if (argc == 2)
{
pathname = argv[1];
}
else if (argc == 3)
{
pathname = argv[1];
pattern = argv[2];
}
else
{
std::cout << "Usage: " << argv[0] << " [PATHNAME] [PATTERN]" << std::endl;
exit (EXIT_FAILURE);
}
try
{
// Initialize ClanLib base components
CL_SetupCore::init();
CL_DirectoryScanner scanner;
bool scan_successfull;
if (pattern.empty ())
scan_successfull = scanner.scan (pathname);
else
scan_successfull = scanner.scan (pathname, pattern);
if (scan_successfull)
{
std::cout << "Searching in " << scanner.get_directory_path();
if (!pattern.empty ())
std::cout << " using pattern '" << pattern << "'" << std::endl;
else
std::cout << std::endl;
while (scanner.next())
{
std::cout << "Found : (" << scanner.get_name() << ")";
if (scanner.is_directory())
std::cout << " == directory";
if (scanner.is_hidden())
std::cout << " [hidden]";
std::cout << std::endl;
}
}
else
{
std::cout << "Directory scan for '" << pathname << "' failed." << std::endl;
}
console.wait_for_key();
CL_SetupCore::deinit();
}
catch(CL_Error error)
{
std::cout << "Exception caught : " << error.message.c_str() << std::endl;
// Display console close message and wait for a key
console.display_close_message();
return -1;
}
return 0;
}
} my_app;
|