最近有一个需求,需要修改EOS名称,将所有文件里面的EOS改为UOS,文件夹名称也需要修改,然后重新构建项目,于是写了一个小程序进行修改。如果有相同项目类似的修改,可以在下面这个程序稍做修改就可以了。

由于时间限制,没有进一步完善,以后有时间再修改一下成为工具。

  EOS version: v1.2.5

  VS version: 2017

  运行环境: win10

  编写代码如下:

  

 #include<iostream>
#include<boost/filesystem.hpp>
#include<boost/filesystem/path.hpp>
#include<boost/filesystem/operations.hpp>
#include<boost/program_options.hpp>
#include<cstring>
#include<vector>
#include<boost/thread.hpp>
#include<boost/container/flat_map.hpp>
#include<algorithm> namespace bpo = boost::program_options;
namespace bfs = boost::filesystem; enum enFileType{
ENU_FILE = ,
ENU_DIR,
}; const uint32_t max_char_line = ;
uint8_t g_lineBuf[max_char_line]; typedef std::set<bfs::path> SetPath; const std::string oldfield = "eos";
const std::string newfield = "uos"; const std::string oldfieldupper = "EOS";
const std::string newfieldupper = "UOS"; bool scanFilesUseRecursive(const std::string& rootPath, SetPath& fileSet);
bfs::path modifyName( bfs::path path);
bool modifyContent(bfs::path path);
char* modify(char* pBuf, uint64_t fsize);
void printPath(const SetPath& fileSet); int main(int argc, char* argv[]) { std::string filePath; bpo::options_description opts("options");
opts.add_options()
("help", "help info")
("dir", bpo::value<std::string>(), "the directory of need to parse"); bpo::variables_map vm;
try {
bpo::store(parse_command_line(argc, argv, opts), vm);
}
catch (bpo::error_with_no_option_name &ex) {
std::cout << ex.what() << std::endl;
} bpo::notify(vm); if (vm.count("help"))
{
std::cout << opts << std::endl;
} if (vm.count("dir"))
{
filePath = vm["dir"].as<std::string>();
} std::string root("\\eos"); bfs::path curPath = bfs::current_path();
std::cout << curPath << std::endl; curPath += root; std::cout << curPath << std::endl; SetPath fileSet; scanFilesUseRecursive(curPath.string(), fileSet);
//printPath(fileSet);
std::cout << fileSet.size() << std::endl; try
{
for (SetPath::reverse_iterator iter = fileSet.rbegin(); iter != fileSet.rend(); ++iter)
{
modifyContent(*iter);
}
}
catch (const std::exception& e)
{
std::cout << std::string("modifyContent exception: ") + e.what() << std::endl;
} try
{
for (SetPath::reverse_iterator iter = fileSet.rbegin(); iter != fileSet.rend(); ++iter)
{
modifyName(*iter);
}
}
catch (const std::exception& e)
{
std::cout << std::string("modifyName exception: ") + e.what() << std::endl;
} system("pause"); return ;
} bool scanFilesUseRecursive(const std::string& rootPath, SetPath& fileSet) { bfs::path fullpath(rootPath, bfs::native); if (!bfs::exists(fullpath))
{
std::cout << std::string("scanFilesUseRecursive : file not exist! ") << rootPath.c_str() << std::endl;
return false;
} bfs::recursive_directory_iterator end_iter; try {
for (bfs::recursive_directory_iterator iter(fullpath); iter != end_iter; iter++) {
fileSet.insert(iter->path());
}
}
catch(bfs::filesystem_error& e)
{
std::cout << e.what() << std::endl;
} return true;
} bfs::path modifyName(const bfs::path path)
{
std::string name = path.filename().string(); size_t pos = name.find(oldfield);
if (pos != std::string::npos)
{
name[pos] = 'u';
} pos = name.find(oldfieldupper);
if (pos != std::string::npos)
{
name[pos] = 'U';
} bfs::path newpath = path.parent_path() / name; bfs::rename(path, newpath); return newpath;
} void printPath(const SetPath& fileSet)
{
for (SetPath::iterator iter = fileSet.begin(); iter != fileSet.end(); ++iter)
{
std::cout << iter->string().c_str() << std::endl;
}
} bool modifyContent(bfs::path path) { if (bfs::is_directory(path)) {
return true;
} std::fstream file;
uint64_t fsize;
char* pBuf = NULL;
try
{
fsize = bfs::file_size(path);
if (fsize == )
{
return true;
} file.open(path.string().c_str(), std::ios::in | std::ios::out | std::ios::binary);
if (!file.is_open())
{
std::cout << "modifyContent() open file failed! path: " << path.string().data() << std::endl;
return false;
} char* pBuf = new char[fsize];
memset(pBuf, , fsize);
file.read(pBuf, fsize);
char* pHead = modify(pBuf, fsize); file.seekg(std::ios::beg);
file.write(pHead, fsize); file.close();
delete pBuf;
pBuf = NULL;
}
catch (const std::exception&)
{
delete pBuf;
file.close();
std::cout << "modifyContent() exception! path: " << path.string().data() << std::endl;
} return true;
} char* modify(char* pBuf, uint64_t fsize)
{
char* ret = pBuf;
uint64_t nCount = ; while (nCount < fsize)
{
if (memcmp(pBuf, oldfield.c_str(), oldfield.length()) == )
{
*pBuf = 'u';
} if (memcmp(pBuf, oldfieldupper.c_str(), oldfieldupper.length()) == )
{
*pBuf = 'U';
} ++nCount;
++pBuf;
} return ret;
}

  把执行文件与目录放在同一级就可以了,运行可能需要2分钟左右,修改完成后,重新编译EOS,会有一个报错,在UOS/libraries/appbase文件下,注释掉version.cmake.in即可编译成功。

EOS 修改文件名称与文件夹名称的更多相关文章

  1. linux 下用renameTo方法修改java web项目中文件夹名称问题

    经测试,在Linux环境中安装tomcat,然后启动其中的项目,在项目中使用java.io.File.renameTo(File dest)方法可行. 之前在本地运行代码可以修改,然后传到Linux服 ...

  2. windows环境下面批量修改文件夹名称

    ren 1 A ren 2 B ren 3 C ren 4 D 电脑桌面新建文档 ---> 批量修改文件夹名称.txt 修改文件名称为:--->批量修改文件夹名称.bat 内容如上: 双击 ...

  3. C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!

    https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...

  4. Java修改文件夹名称

    Java修改文件夹名称 学习了:http://blog.csdn.net/yongh701/article/details/45063833 进行文件夹名字批量修改,注意,要写全路径: package ...

  5. 中文Ubuntu系统根目录文件夹名称变为英文

    Ubuntu中文安装后,家目录均为中文,如“下载” “文档”等等,在使用Shell时很不方便,可用如下方法将这些文件夹名称改回英文 1.使用命令 export LANG=en_US xdg-user- ...

  6. R8—批量生成文件夹,批量读取文件夹名称+R文件管理系统操作函数

    一. 批量生成文件夹,批量读取文件夹名称 今日,工作中遇到这样一个问题:boss给我们提供了200多家公司的ID代码(如6007.7920等),需要根据这些ID号去搜索下载新闻,从而将下载到的新闻存到 ...

  7. [转]win7下修改C盘USERS文件下的名称

    Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改   Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改 Win7下C:\Users\Co ...

  8. 将Ubuntu主文件夹里的中文文件夹名称改成英文

    方法一: 首先修改现有主文件夹下各文件夹名称: Desktop. Documents. Download. Music. Pictures. Public. Templates. Videos …… ...

  9. [转]gnome环境中将家目录下预设的文件夹由中文名称改为英文名称

    参考文章:gnome环境中将家目录下预设的文件夹由中文名称改为英文名称 打开终端 1 修改语言环境为英文 export LANG=en_US 如果想修改语言环境为日语,可执行 export LANG= ...

随机推荐

  1. pa15-三省吾身

    序号 项 1 凡事提前10分钟    凡事提前10分钟,会让你有充裕的时间应对可能的突发事件,更加从容.    试着把起床闹钟提前10分钟,你就会发现你出门不必急匆匆,早饭也可慢慢享用,一整天的状态也 ...

  2. java 多线程系列基础篇(五)之线程等待与唤醒

    1.wait(), notify(), notifyAll()等方法介绍 在Object.java中,定义了wait(), notify()和notifyAll()等接口.wait()的作用是让当前线 ...

  3. Stun方式的P2P实现原理(转)

    转帖地址:http://www.cppblog.com/peakflys/archive/2013/01/25/197562.html   二.STUN方式的P2P实现 STUN是RFC3489规定的 ...

  4. 使用git将代码传到github

    廖雪峰git教程:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 注:add加入 ...

  5. JSON数据格式简介

    ---------------siwuxie095                         JSON 简介     JSON:JavaScript 对象表示法(JavaScript Objec ...

  6. 猪羊——HTML解析

    HTML标签和属性大全见:http://www.cnblogs.com/Mr-liyang/p/5797976.html CSS样式大全:http://www.cnblogs.com/Mr-liyan ...

  7. final 子类禁止重写

    <?php //子类中编写和父类中完全一样的函数,是对父类中的函数进行重写 class BaseClass{ public function test() { echo "BaseCl ...

  8. function几种自执行的形式

    1.(function(){})();这种是最常用的形式 2.var t = function(){}(); 3.-function(){}(); 这三种形式都能自执行

  9. 914D Bash and a Tough Math Puzzle

    传送门 分析 用线段树维护区间gcd,每次查询找到第一个不是x倍数的点,如果这之后还有gcd不能被x整除的区间则这个区间不合法 代码 #include<iostream> #include ...

  10. ZROI2018提高day2t1

    传送门 分析 考场上写了前20分和|a[i]|<=1的情况,但是因为没开long long爆零了.实际考场上差不多想到正解了,至少当时不会凸壳... 我们发现对于ax2+bx的大小关系我们可以将 ...