最近有一个需求,需要修改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. mybatis 学习四(下) SQL语句映射文件增删改查、参数、缓存

    2.2 select 一个select 元素非常简单.例如: <!-- 查询学生,根据id --> <select id="getStudent" paramet ...

  2. Spring学习十 rest

    1:  Web  service:  是一个大的概念范畴,它表现了一种设计思想 SOAP 是 Web service 的一个重要组成部份. SOAP 是一种协议而非详细产品.SOAP 是通过 XML ...

  3. python操作excel的读写

    1.下载xlrd和xlwt pip install xlwd pip install xlrd pip install xlutils 2.读写操作(已存在的excel) #-*- coding:ut ...

  4. DHCP工作工程

    1.客户端请求IP 客户端发一个DHCP DISCOVEY(包含主机名.mac地址)广播包 2.服务端响应请求 DHCP服务器收到请求后,查看自己的地址池是否有合法的地址.如果有,广播一个DHCP o ...

  5. 定位程序问题出现的原因工具-jstack

    jstack还可以生成线程快照 如何使用jstack: 1.打开命令行,输入jstack 在任务管理器中就可看到对应进程id 2.在命令行中输入 jstack -l 进程id 这样就可得到进程中所有的 ...

  6. day17-jdbc 6.Connection介绍

    package cn.itcast.jdbc; import com.mysql.jdbc.Connection; import java.sql.DriverManager; import java ...

  7. 浏览器默认标签样式总结及css初始化程序(转)

    浏览器默认标签样式总结及css初始化程序   html中的大部分的标签都有一些糟糕的样式,有的是标签天然自带的,有的是浏览器默认设置的,我们在写网页时,这些默认的样式就会时不时的跳出来捣一下乱,搞得我 ...

  8. sleep()和usleep()

    函数名: sleep头文件: #include <windows.h> // 在VC中使用带上头文件        #include <unistd.h>  // 在gcc编译 ...

  9. 面试题: Struts2

    1. Struts2与Struts1的联系与区别是什么?为什么要用Struts2? 答案: struts1与struts2都是mvc框架的经典实现模式. Struts2不是从Struts1升级而来,而 ...

  10. Linux共享对象之编译参数 -fPIC

    转载自:https://www.cnblogs.com/cswuyg/p/3830703.html     在Linux系统中,动态链接文件称为动态共享对象(DSO,Dynamic Shared Ob ...