Created
May 8, 2018 08:46
-
-
Save ReimuNotMoe/8a50af6c78cea63cdf1fde50a1d88100 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
photo-renamer | |
Copyright (C) 2018 ReimuNotMoe <reimuhatesfdt@gmail.com> | |
photo-renamer is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
photo-renamer is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with photo-renamer. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
#include <cstdio> | |
#include <cstdlib> | |
#include <dirent.h> | |
#include <sys/types.h> | |
#include <string> | |
#include <cstring> | |
using namespace std; | |
int main(int argc, char **argv) { | |
DIR *thisdir = opendir("."); | |
dirent *thisent; | |
while ((thisent = readdir(thisdir))) { | |
printf("%s => ", thisent->d_name); | |
string newname; | |
size_t ent_len = strlen(thisent->d_name); | |
for (size_t j=0; j<ent_len; j++) { | |
if (isdigit(thisent->d_name[j])) { | |
newname += thisent->d_name[j]; | |
if (newname.size() == 8) | |
newname += '_'; | |
} | |
} | |
if (newname.empty()) { | |
puts("Bad"); | |
continue; | |
} | |
char *dotplace = strrchr(thisent->d_name, '.'); | |
if (!dotplace){ | |
puts("Bad"); | |
continue; | |
} | |
string suffix = dotplace; | |
if (newname.size() == 15) { | |
string newfullname; | |
if (argv[1]) | |
newfullname += "Screenshot"; | |
else | |
newfullname += "IMG"; | |
newfullname += "_"; | |
newfullname += newname; | |
// newfullname += "."; | |
newfullname += suffix; | |
puts(newfullname.c_str()); | |
rename(thisent->d_name, newfullname.c_str()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment