main.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. file_getFolderContent(folderPath, [indentation](ReadableString entryPath, EntryType entryType) {
  16. ReadableString shortName = file_getPathlessName(entryPath);
  17. if (entryType == EntryType::Folder) {
  18. printText(indentation, " Folder(", shortName, ")\n");
  19. exploreFolder(entryPath, indentation + " ");
  20. } else if (entryType == EntryType::File) {
  21. printText(indentation, " File(", shortName, ") of ", file_getSize(entryPath), " bytes\n");
  22. }
  23. });
  24. }
  25. int main(int argn, NativeChar **argv) {
  26. List<String> args = file_convertInputArguments(argn, argv);
  27. printText("Input arguments:\n");
  28. for (int a = 0; a < args.length(); a++) {
  29. printText(" args[", a, "] = ", args[a], "\n");
  30. }
  31. String absolutePath = file_getCanonicalPath(args[0]);
  32. printText("Absolute path = ", absolutePath, "\n");
  33. if (args.length() > 1) {
  34. // Explore each listed folder from input arguments.
  35. for (int a = 1; a < args.length(); a++) {
  36. printText("Exploring ", args[a], "\n");
  37. exploreFolder(args[a], U"");
  38. }
  39. } else {
  40. // Test program on the current path when nothing was entered.
  41. String currentPath = file_getCurrentPath();
  42. printText("Exploring ", currentPath, " because no folders were given.\n");
  43. exploreFolder(currentPath, U"");
  44. }
  45. }