#include #include "filefunctions.h" #include "debugging.h" #include #include #include #include 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 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"); 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"); 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; }