Skip to content

Instantly share code, notes, and snippets.

@plasma-effect
Created August 30, 2019 02:10
Show Gist options
  • Save plasma-effect/fd298b8c2e260b30741332d09b47892f to your computer and use it in GitHub Desktop.
Save plasma-effect/fd298b8c2e260b30741332d09b47892f to your computer and use it in GitHub Desktop.
指定したディレクトリ内のファイルのサフィックスにくっついた括弧を除去するやつ
#include<iostream>
#include<string>
#include<filesystem>
int main()
{
std::string path;
std::getline(std::cin, path);
for (auto&& x : std::filesystem::recursive_directory_iterator(path))
{
std::cout << x.path() << std::endl;
if (!x.is_directory())
{
auto base = x.path().string();
auto to = base;
auto end = std::prev(to.end());
for (; end != to.begin() && *end != '.'; --end);
auto start = end;
for (; start != to.begin() && *start != '('; --start);
if (start != to.begin())
{
to.erase(std::prev(start), end);
std::filesystem::rename(base, to);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment