#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()); */ printf("\n\n\n\n"); DEBUG("Test operator: " << (CF_RECURSIVE | CF_RELATIVE)); std::queue files; ls("", files, CF_RECURSIVE | CF_RELATIVE); while(files.size()) { File_Struct temp = files.front(); files.pop(); DEBUG("Fil: " << temp.path); if(temp.file_ending == "exe") { if(temp.modified) delete temp.modified; continue; } //DEBUG("Modified: " << asctime(temp.modified)); /* if(temp.taken) DEBUG("Tagen: " << asctime(temp.taken)); */ std::ostringstream new_path; new_path << pwd() << "\\sorterat\\"; if(temp.taken) { DEBUG("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) { DEBUG("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); } DEBUG("New filename: " << new_path.str() << "\n\n"); // Free memory if(temp.taken) delete temp.taken; if(temp.modified) delete temp.modified; } printf("Klart utan jättefatala fel troligtvis! :D\n"); char c; std::cin >> c; return 0; }