EOS 修改文件名称与文件夹名称
最近有一个需求,需要修改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 修改文件名称与文件夹名称的更多相关文章
- linux 下用renameTo方法修改java web项目中文件夹名称问题
经测试,在Linux环境中安装tomcat,然后启动其中的项目,在项目中使用java.io.File.renameTo(File dest)方法可行. 之前在本地运行代码可以修改,然后传到Linux服 ...
- windows环境下面批量修改文件夹名称
ren 1 A ren 2 B ren 3 C ren 4 D 电脑桌面新建文档 ---> 批量修改文件夹名称.txt 修改文件名称为:--->批量修改文件夹名称.bat 内容如上: 双击 ...
- C# 选择文件、选择文件夹、打开文件(或者文件夹) 路径中获取文件全路径、目录、扩展名、文件名称 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名!!
https://www.cnblogs.com/zhlziliaoku/p/5241097.html 1.选择文件用OpenDialog OpenFileDialog dialog = new Ope ...
- Java修改文件夹名称
Java修改文件夹名称 学习了:http://blog.csdn.net/yongh701/article/details/45063833 进行文件夹名字批量修改,注意,要写全路径: package ...
- 中文Ubuntu系统根目录文件夹名称变为英文
Ubuntu中文安装后,家目录均为中文,如“下载” “文档”等等,在使用Shell时很不方便,可用如下方法将这些文件夹名称改回英文 1.使用命令 export LANG=en_US xdg-user- ...
- R8—批量生成文件夹,批量读取文件夹名称+R文件管理系统操作函数
一. 批量生成文件夹,批量读取文件夹名称 今日,工作中遇到这样一个问题:boss给我们提供了200多家公司的ID代码(如6007.7920等),需要根据这些ID号去搜索下载新闻,从而将下载到的新闻存到 ...
- [转]win7下修改C盘USERS文件下的名称
Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改 Win7下C:\Users\Cortana以账户名称命名的系统文件夹用户名的修改 Win7下C:\Users\Co ...
- 将Ubuntu主文件夹里的中文文件夹名称改成英文
方法一: 首先修改现有主文件夹下各文件夹名称: Desktop. Documents. Download. Music. Pictures. Public. Templates. Videos …… ...
- [转]gnome环境中将家目录下预设的文件夹由中文名称改为英文名称
参考文章:gnome环境中将家目录下预设的文件夹由中文名称改为英文名称 打开终端 1 修改语言环境为英文 export LANG=en_US 如果想修改语言环境为日语,可执行 export LANG= ...
随机推荐
- Python数据库(三)-使用sqlalchemy创建表
首先需要安装sqlalchemy根据所需情况调用数据库接口,对数据库进行操作pymysql:mysql+pymysql://<username>:<password>@< ...
- 2016.8.11 DataTable合并及排除重复方法
合并: DataTable pros=xxx; DataTable pstar=yyy; //将两张DataTable合成一张 foreach (DataRow dr in pstar.Rows) { ...
- springmvc下的省市县三级联动
转自:https://blog.csdn.net/rentian1/article/details/77662635
- Android CTS
1.什么是CTS CTS是google制定的兼容性测试包(Compatibility Test Suite),只有通过CTS测试的设备才有可能获得Android的商标和享受Android Market ...
- 关于handler的再次讨论
主要有两个问题,post方法和sendmessage方法有什么不同? 同一个handler对象发送的message只能发送给自己吗? 问题1: post方法,对于Handler的Post方式来说,它会 ...
- springboot启动过程(1)-初始化
1 springboot启动时,只需要调用一个类前面加了@SpringBootApplication的main函数,执行SpringApplication.run(DemoApplication. ...
- day18-事务与连接池 3.jdbc中事务操作介绍
那么我们都是通过程序操作数据库.所以要了解jdbc下怎样对事务操作.jdbc如何操作事务? 自动事务false那就不开了呗相当于开启事务. package cn.itcast.transaction; ...
- String/StringBuilder 类 用对象数组实现登录注册功能
一.需求说明:实现用户注册.登陆功能: 程序中使用一个长度为3的对象数组,存储用户的登录名和密码: 例如如下格式: 登录名 密码 生日 爱好 zhangsan 11 ...
- 面试题: Struts2
1. Struts2与Struts1的联系与区别是什么?为什么要用Struts2? 答案: struts1与struts2都是mvc框架的经典实现模式. Struts2不是从Struts1升级而来,而 ...
- JDK并发包2-线程池