main.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <cstdio>
  2. #include "filefunctions.h"
  3. #include "debugging.h"
  4. #include <windows.h>
  5. #include <sstream>
  6. #include <string>
  7. #include <iomanip>
  8. using namespace filefunctions;
  9. int main(int argc, char **argv)
  10. {
  11. printf("Yo dude!\n");
  12. DEBUG(std::hex << INVALID_FILE_ATTRIBUTES << std::endl << argv[0]);
  13. cd();
  14. /*
  15. if(cd("testfiler", CF_RELATIVE))
  16. printf("FAIL!\n");
  17. else
  18. printf("SUCCESS! Current dir: %s\n", pwd().c_str());
  19. */
  20. printf("\n\n\n\n");
  21. DEBUG("Test operator: " << (CF_RECURSIVE | CF_RELATIVE));
  22. std::queue<File_Struct> files;
  23. ls("", files, CF_RECURSIVE | CF_RELATIVE);
  24. while(files.size())
  25. {
  26. File_Struct temp = files.front();
  27. files.pop();
  28. DEBUG("Fil: " << temp.path);
  29. if(temp.file_ending == "exe")
  30. {
  31. if(temp.modified)
  32. delete temp.modified;
  33. continue;
  34. }
  35. //DEBUG("Modified: " << asctime(temp.modified));
  36. /*
  37. if(temp.taken)
  38. DEBUG("Tagen: " << asctime(temp.taken));
  39. */
  40. std::ostringstream new_path;
  41. new_path << pwd() << "\\sorterat\\";
  42. if(temp.taken)
  43. {
  44. DEBUG("Moving based on date taken");
  45. new_path << (temp.taken->tm_year+1900) << "\\" << std::setfill('0') << std::setw(2) << (temp.taken->tm_mon+1) << "\\" << (temp.taken->tm_year+1900) << "-" << std::setw(2) << (temp.taken->tm_mon+1) << "-" \
  46. << std::setw(2) << temp.taken->tm_mday << "_" << std::setw(2) << temp.taken->tm_hour << "'" << std::setw(2) << temp.taken->tm_min << "'" << std::setw(2) << temp.taken->tm_sec;
  47. }
  48. else if(temp.modified)
  49. {
  50. DEBUG("Moving based on date modified");
  51. new_path << (temp.modified->tm_year+1900) << "\\" << std::setfill('0') << std::setw(2) << (temp.modified->tm_mon+1) << "\\" << (temp.modified->tm_year+1900) << "-" << std::setw(2) << (temp.modified->tm_mon+1) << "-" \
  52. << std::setw(2) << temp.modified->tm_mday << "_" << std::setw(2) << temp.modified->tm_hour << "'" << std::setw(2) << temp.modified->tm_min << "'" << std::setw(2) << temp.modified->tm_sec;
  53. }
  54. else
  55. {
  56. DEBUG("No date found");
  57. new_path << "osorterat/" << temp.path.substr(temp.path.find_last_of('/\\')+1, temp.path.find_last_of('.'));
  58. }
  59. std::ostringstream path_postfix;
  60. path_postfix << new_path.str() << "." << temp.file_ending;
  61. if(mv(temp.path, path_postfix.str(), CF_NONE) == SC_ALREADY_EXISTS)
  62. {
  63. int postfix = 1;
  64. do
  65. {
  66. path_postfix.str("");
  67. path_postfix << new_path.str() << "(" << postfix++ << ")" << "." << temp.file_ending;
  68. } while(mv(temp.path, path_postfix.str()) == SC_ALREADY_EXISTS);
  69. }
  70. DEBUG("New filename: " << new_path.str() << "\n\n");
  71. // Free memory
  72. if(temp.taken)
  73. delete temp.taken;
  74. if(temp.modified)
  75. delete temp.modified;
  76. }
  77. printf("Klart utan jättefatala fel troligtvis! :D\n");
  78. char c;
  79. std::cin >> c;
  80. return 0;
  81. }