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= ...
随机推荐
- mybatis 学习三 关键文件解析
1: mybatis-config.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYP ...
- createprocess并行运算
#include "stdafx.h"#include "windows.h"#include <iostream> using namespace ...
- 部署和调优 1.1 nfs部署和优化-2
更改共享目录文件默认的所有者和所属组 已知道客户端有个user11用户 cat /etc/passwd user11:x:501:501::/home/user11:/bin/bash 服务端打开 v ...
- tomcat跑多个项目和不同端口访问项目
最近笔者在工作中需要同时运行多个项目,且有时需要不同端口访问项目:在此过程中,笔者觉得有必要将注意事项记录一下,以备后边查阅或广大读者借鉴. 工作环境是win7,64位,IDE为eclipse,浏览器 ...
- Android CTS(frome google)
Compatibility Test Suite How does the CTS work? The Compatibility Test Suite (CTS) is a free, commer ...
- 【Android异常】The specified child already has a parent. You must call removeView() on the child's parent first.
错误信息: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must ...
- 第二部分 实习操作课程 第一节 ArcGIS Online的基本功能
- Codeforces 1110D Jongmah (DP)
题意:你有n个数字,范围[1, m],你可以选择其中的三个数字构成一个三元组,但是这三个数字必须是连续的或者相同的,每个数字只能用一次,问这n个数字最多构成多少个三元组? 解析:首先我们容易发现,我们 ...
- Linux 使用静态库注意事项
1. 静态库一定要放在生成文件后面 gcc main.c -o main libhello.a 2. 使用静态库时一定要连接所有用到的静态库 gcc main.c -o main liba.a lib ...
- Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at ExTestDrive.main ...