main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. std::queue<File_Struct> files;
  21. ls("", files, CF_RECURSIVE | CF_RELATIVE);
  22. std::cout << "Klar med listning av filer. Flyttar nu enl. önskemål" << std::endl;
  23. while(files.size())
  24. {
  25. File_Struct temp = files.front();
  26. DEBUG("Fil: " << temp.path);
  27. if(temp.file_ending == "exe")
  28. {
  29. if(temp.modified)
  30. delete temp.modified;
  31. files.pop();
  32. continue;
  33. }
  34. //DEBUG("Modified: " << asctime(temp.modified));
  35. /*
  36. if(temp.taken)
  37. DEBUG("Tagen: " << asctime(temp.taken));
  38. */
  39. INFO("Moving file: \"" << temp.path << "\"");
  40. std::ostringstream new_path;
  41. new_path << std::dec << pwd() << "\\sorterat\\";
  42. if(temp.taken)
  43. {
  44. INFO("Moving based on date taken");
  45. DEBUG("__GET_EXIF_TIME__ year: " << temp.taken->tm_year);
  46. DEBUG("__GET_EXIF_TIME__ month: " << temp.taken->tm_mon);
  47. DEBUG("__GET_EXIF_TIME__ date: " << temp.taken->tm_mday);
  48. DEBUG("__GET_EXIF_TIME__ hour: " << temp.taken->tm_hour);
  49. DEBUG("__GET_EXIF_TIME__ minute: " << temp.taken->tm_min);
  50. DEBUG("__GET_EXIF_TIME__ second: " << temp.taken->tm_sec);
  51. 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) << "-" \
  52. << 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;
  53. }
  54. else if(temp.modified)
  55. {
  56. INFO("Moving based on date modified");
  57. DEBUG("__GET_EXIF_TIME__ year: " << temp.modified->tm_year);
  58. DEBUG("__GET_EXIF_TIME__ month: " << temp.modified->tm_mon);
  59. DEBUG("__GET_EXIF_TIME__ date: " << temp.modified->tm_mday);
  60. DEBUG("__GET_EXIF_TIME__ hour: " << temp.modified->tm_hour);
  61. DEBUG("__GET_EXIF_TIME__ minute: " << temp.modified->tm_min);
  62. DEBUG("__GET_EXIF_TIME__ second: " << temp.modified->tm_sec);
  63. 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) << "-" \
  64. << 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;
  65. }
  66. else
  67. {
  68. DEBUG("No date found");
  69. new_path << "osorterat\\" << temp.path.substr(temp.path.find_last_of('/\\')+1, temp.path.find_last_of('.'));
  70. }
  71. std::ostringstream path_postfix;
  72. path_postfix << new_path.str() << "." << temp.file_ending;
  73. if(mv(temp.path, path_postfix.str(), CF_NONE) == SC_ALREADY_EXISTS)
  74. {
  75. int postfix = 1;
  76. do
  77. {
  78. path_postfix.str("");
  79. path_postfix << new_path.str() << "(" << postfix++ << ")" << "." << temp.file_ending;
  80. } while(mv(temp.path, path_postfix.str()) == SC_ALREADY_EXISTS);
  81. }
  82. INFO("New filename: " << path_postfix.str() << "\n\n");
  83. // Free memory
  84. if(temp.taken)
  85. delete temp.taken;
  86. if(temp.modified)
  87. delete temp.modified;
  88. files.pop();
  89. }
  90. printf("Klart! :D\n");
  91. char c;
  92. std::cin >> c;
  93. return 0;
  94. }