| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #include <cstdio>
- #include "filefunctions.h"
- #include "debugging.h"
- #include <windows.h>
- #include <sstream>
- #include <string>
- #include <iomanip>
- using namespace filefunctions;
- int main(int argc, char **argv)
- {
- printf("Yo dude!\n");
- DEBUG(std::hex << INVALID_FILE_ATTRIBUTES << std::endl << argv[0]);
- cd();
- /*
- if(cd("testfiler", CF_RELATIVE))
- printf("FAIL!\n");
- else
- printf("SUCCESS! Current dir: %s\n", pwd().c_str());
- */
- std::queue<File_Struct> files;
- ls("", files, CF_RECURSIVE | CF_RELATIVE);
- std::cout << "Klar med listning av filer. Flyttar nu enl. önskemål" << std::endl;
- while(files.size())
- {
- File_Struct temp = files.front();
- DEBUG("Fil: " << temp.path);
- if(temp.file_ending == "exe")
- {
- if(temp.modified)
- delete temp.modified;
- files.pop();
- continue;
- }
- //DEBUG("Modified: " << asctime(temp.modified));
- /*
- if(temp.taken)
- DEBUG("Tagen: " << asctime(temp.taken));
- */
- INFO("Moving file: \"" << temp.path << "\"");
- std::ostringstream new_path;
- new_path << std::dec << pwd() << "\\sorterat\\";
- if(temp.taken)
- {
- INFO("Moving based on date taken");
- DEBUG("__GET_EXIF_TIME__ year: " << temp.taken->tm_year);
- DEBUG("__GET_EXIF_TIME__ month: " << temp.taken->tm_mon);
- DEBUG("__GET_EXIF_TIME__ date: " << temp.taken->tm_mday);
- DEBUG("__GET_EXIF_TIME__ hour: " << temp.taken->tm_hour);
- DEBUG("__GET_EXIF_TIME__ minute: " << temp.taken->tm_min);
- DEBUG("__GET_EXIF_TIME__ second: " << temp.taken->tm_sec);
- 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) << "-" \
- << 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;
- }
- else if(temp.modified)
- {
- INFO("Moving based on date modified");
- DEBUG("__GET_EXIF_TIME__ year: " << temp.modified->tm_year);
- DEBUG("__GET_EXIF_TIME__ month: " << temp.modified->tm_mon);
- DEBUG("__GET_EXIF_TIME__ date: " << temp.modified->tm_mday);
- DEBUG("__GET_EXIF_TIME__ hour: " << temp.modified->tm_hour);
- DEBUG("__GET_EXIF_TIME__ minute: " << temp.modified->tm_min);
- DEBUG("__GET_EXIF_TIME__ second: " << temp.modified->tm_sec);
- 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) << "-" \
- << 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;
- }
- else
- {
- DEBUG("No date found");
- new_path << "osorterat\\" << temp.path.substr(temp.path.find_last_of('/\\')+1, temp.path.find_last_of('.'));
- }
- std::ostringstream path_postfix;
- path_postfix << new_path.str() << "." << temp.file_ending;
- if(mv(temp.path, path_postfix.str(), CF_NONE) == SC_ALREADY_EXISTS)
- {
- int postfix = 1;
- do
- {
- path_postfix.str("");
- path_postfix << new_path.str() << "(" << postfix++ << ")" << "." << temp.file_ending;
- } while(mv(temp.path, path_postfix.str()) == SC_ALREADY_EXISTS);
- }
- INFO("New filename: " << path_postfix.str() << "\n\n");
- // Free memory
- if(temp.taken)
- delete temp.taken;
- if(temp.modified)
- delete temp.modified;
- files.pop();
- }
- printf("Klart! :D\n");
- char c;
- std::cin >> c;
- return 0;
- }
|