main.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 
  2. // A file finding application showing how to use the filesystem wrapper in the file API using C++ 2014.
  3. #include "../../DFPSR/includeFramework.h"
  4. using namespace dsr;
  5. void exploreFolder(const ReadableString& folderPath, const ReadableString& indentation) {
  6. if (!file_getFolderContent(folderPath, [indentation](const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType) {
  7. printText(indentation, "* Entry: ", entryName, " as ", entryType, "\n");
  8. if (entryType == EntryType::Folder) {
  9. exploreFolder(entryPath, indentation + " ");
  10. }
  11. })) {
  12. printText("Failed to explore ", folderPath, "\n");
  13. }
  14. }
  15. DSR_MAIN_CALLER(dsrMain)
  16. void dsrMain(List<String> args) {
  17. printText("Input arguments:\n");
  18. for (int a = 0; a < args.length(); a++) {
  19. printText(" args[", a, "] = ", args[a], "\n");
  20. }
  21. String absolutePath = file_getAbsolutePath(args[0]);
  22. printText("Absolute path = ", absolutePath, "\n");
  23. if (args.length() > 1) {
  24. // Explore each listed folder from input arguments.
  25. for (int a = 1; a < args.length(); a++) {
  26. printText("Exploring ", args[a], "\n");
  27. exploreFolder(args[a], U" ");
  28. }
  29. } else {
  30. // Test program on the current path when nothing was entered.
  31. String currentPath = file_getCurrentPath();
  32. printText("Exploring ", currentPath, " because no folders were given.\n");
  33. exploreFolder(currentPath, U" ");
  34. }
  35. }