main.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 
  2. // A file finding application showing how to use the filesystem wrapper in the file API using C++ 2017.
  3. /*
  4. TODO:
  5. * Function for getting EntryType from a path.
  6. * Implement file_getParent, getting the parent folder or root path, so that it's easy to iterate the other way.
  7. * Something for listing root paths, so that systems with more than one system root can have a listbox with drives to select in file explorers.
  8. * Wrap file_getPermissions
  9. * Wrap file_moveAndRename (over std::filesystem::rename)
  10. * Wrap copy (over std::filesystem::copy)
  11. */
  12. #include "../../DFPSR/includeFramework.h"
  13. using namespace dsr;
  14. void exploreFolder(const ReadableString& folderPath, const ReadableString& indentation) {
  15. if (!file_getFolderContent(folderPath, [indentation](const ReadableString& entryPath, const ReadableString& entryName, EntryType entryType) {
  16. printText(indentation, "* Entry: ", entryName, " as ", entryType, "\n");
  17. if (entryType == EntryType::Folder) {
  18. exploreFolder(entryPath, indentation + " ");
  19. }
  20. })) {
  21. printText("Failed to explore ", folderPath, "\n");
  22. }
  23. }
  24. DSR_MAIN_CALLER(dsrMain)
  25. void dsrMain(List<String> args) {
  26. printText("Input arguments:\n");
  27. for (int a = 0; a < args.length(); a++) {
  28. printText(" args[", a, "] = ", args[a], "\n");
  29. }
  30. String absolutePath = file_getAbsolutePath(args[0]);
  31. printText("Absolute path = ", absolutePath, "\n");
  32. if (args.length() > 1) {
  33. // Explore each listed folder from input arguments.
  34. for (int a = 1; a < args.length(); a++) {
  35. printText("Exploring ", args[a], "\n");
  36. exploreFolder(args[a], U" ");
  37. }
  38. } else {
  39. // Test program on the current path when nothing was entered.
  40. String currentPath = file_getCurrentPath();
  41. printText("Exploring ", currentPath, " because no folders were given.\n");
  42. exploreFolder(currentPath, U" ");
  43. }
  44. }