EOS 修改文件名称与文件夹名称
最近有一个需求,需要修改EOS名称,将所有文件里面的EOS改为UOS,文件夹名称也需要修改,然后重新构建项目,于是写了一个小程序进行修改。如果有相同项目类似的修改,可以在下面这个程序稍做修改就可以了。
由于时间限制,没有进一步完善,以后有时间再修改一下成为工具。
EOS version: v1.2.5
VS version: 2017
运行环境: win10
编写代码如下:
1 #include<iostream> 2 #include<boost/filesystem.hpp> 3 #include<boost/filesystem/path.hpp> 4 #include<boost/filesystem/operations.hpp> 5 #include<boost/program_options.hpp> 6 #include<cstring> 7 #include<vector> 8 #include<boost/thread.hpp> 9 #include<boost/container/flat_map.hpp> 10 #include<algorithm> 11 12 13 namespace bpo = boost::program_options; 14 namespace bfs = boost::filesystem; 15 16 17 enum enFileType{ 18 ENU_FILE = 1, 19 ENU_DIR, 20 }; 21 22 const uint32_t max_char_line = 65535; 23 uint8_t g_lineBuf[max_char_line]; 24 25 typedef std::set<bfs::path> SetPath; 26 27 const std::string oldfield = "eos"; 28 const std::string newfield = "uos"; 29 30 const std::string oldfieldupper = "EOS"; 31 const std::string newfieldupper = "UOS"; 32 33 34 bool scanFilesUseRecursive(const std::string& rootPath, SetPath& fileSet); 35 bfs::path modifyName( bfs::path path); 36 bool modifyContent(bfs::path path); 37 char* modify(char* pBuf, uint64_t fsize); 38 void printPath(const SetPath& fileSet); 39 40 int main(int argc, char* argv[]) { 41 42 std::string filePath; 43 44 bpo::options_description opts("options"); 45 opts.add_options() 46 ("help", "help info") 47 ("dir", bpo::value<std::string>(), "the directory of need to parse"); 48 49 bpo::variables_map vm; 50 try { 51 bpo::store(parse_command_line(argc, argv, opts), vm); 52 } 53 catch (bpo::error_with_no_option_name &ex) { 54 std::cout << ex.what() << std::endl; 55 } 56 57 bpo::notify(vm); 58 59 if (vm.count("help")) 60 { 61 std::cout << opts << std::endl; 62 } 63 64 if (vm.count("dir")) 65 { 66 filePath = vm["dir"].as<std::string>(); 67 } 68 69 std::string root("\\eos"); 70 71 bfs::path curPath = bfs::current_path(); 72 std::cout << curPath << std::endl; 73 74 curPath += root; 75 76 std::cout << curPath << std::endl; 77 78 SetPath fileSet; 79 80 scanFilesUseRecursive(curPath.string(), fileSet); 81 //printPath(fileSet); 82 std::cout << fileSet.size() << std::endl; 83 84 try 85 { 86 for (SetPath::reverse_iterator iter = fileSet.rbegin(); iter != fileSet.rend(); ++iter) 87 { 88 modifyContent(*iter); 89 } 90 } 91 catch (const std::exception& e) 92 { 93 std::cout << std::string("modifyContent exception: ") + e.what() << std::endl; 94 } 95 96 try 97 { 98 for (SetPath::reverse_iterator iter = fileSet.rbegin(); iter != fileSet.rend(); ++iter) 99 { 100 modifyName(*iter); 101 } 102 } 103 catch (const std::exception& e) 104 { 105 std::cout << std::string("modifyName exception: ") + e.what() << std::endl; 106 } 107 108 system("pause"); 109 110 return 0; 111 } 112 113 114 bool scanFilesUseRecursive(const std::string& rootPath, SetPath& fileSet) { 115 116 bfs::path fullpath(rootPath, bfs::native); 117 118 if (!bfs::exists(fullpath)) 119 { 120 std::cout << std::string("scanFilesUseRecursive : file not exist! ") << rootPath.c_str() << std::endl; 121 return false; 122 } 123 124 bfs::recursive_directory_iterator end_iter; 125 126 try { 127 for (bfs::recursive_directory_iterator iter(fullpath); iter != end_iter; iter++) { 128 fileSet.insert(iter->path()); 129 } 130 } 131 catch(bfs::filesystem_error& e) 132 { 133 std::cout << e.what() << std::endl; 134 } 135 136 return true; 137 } 138 139 bfs::path modifyName(const bfs::path path) 140 { 141 std::string name = path.filename().string(); 142 143 size_t pos = name.find(oldfield); 144 if (pos != std::string::npos) 145 { 146 name[pos] = 'u'; 147 } 148 149 pos = name.find(oldfieldupper); 150 if (pos != std::string::npos) 151 { 152 name[pos] = 'U'; 153 } 154 155 bfs::path newpath = path.parent_path() / name; 156 157 bfs::rename(path, newpath); 158 159 return newpath; 160 } 161 162 void printPath(const SetPath& fileSet) 163 { 164 for (SetPath::iterator iter = fileSet.begin(); iter != fileSet.end(); ++iter) 165 { 166 std::cout << iter->string().c_str() << std::endl; 167 } 168 } 169 170 bool modifyContent(bfs::path path) { 171 172 if (bfs::is_directory(path)) { 173 return true; 174 } 175 176 std::fstream file; 177 uint64_t fsize; 178 char* pBuf = NULL; 179 try 180 { 181 fsize = bfs::file_size(path); 182 if (fsize == 0) 183 { 184 return true; 185 } 186 187 file.open(path.string().c_str(), std::ios::in | std::ios::out | std::ios::binary); 188 if (!file.is_open()) 189 { 190 std::cout << "modifyContent() open file failed! path: " << path.string().data() << std::endl; 191 return false; 192 } 193 194 char* pBuf = new char[fsize]; 195 memset(pBuf, 0, fsize); 196 file.read(pBuf, fsize); 197 char* pHead = modify(pBuf, fsize); 198 199 file.seekg(std::ios::beg); 200 file.write(pHead, fsize); 201 202 file.close(); 203 delete pBuf; 204 pBuf = NULL; 205 } 206 catch (const std::exception&) 207 { 208 delete pBuf; 209 file.close(); 210 std::cout << "modifyContent() exception! path: " << path.string().data() << std::endl; 211 } 212 213 return true; 214 } 215 216 char* modify(char* pBuf, uint64_t fsize) 217 { 218 char* ret = pBuf; 219 uint64_t nCount = 0; 220 221 while (nCount < fsize) 222 { 223 if (memcmp(pBuf, oldfield.c_str(), oldfield.length()) == 0) 224 { 225 *pBuf = 'u'; 226 } 227 228 if (memcmp(pBuf, oldfieldupper.c_str(), oldfieldupper.length()) == 0) 229 { 230 *pBuf = 'U'; 231 } 232 233 ++nCount; 234 ++pBuf; 235 } 236 237 return ret; 238 }
把执行文件与目录放在同一级就可以了,运行可能需要2分钟左右,修改完成后,重新编译EOS,会有一个报错,在UOS/libraries/appbase文件下,注释掉version.cmake.in即可编译成功。
转载于:https://www.cnblogs.com/hbright/p/9721805.html
EOS 修改文件名称与文件夹名称相关推荐
- C#修改解决方案的名称 和解决方案文件夹的名称 ,及项目程序名称,项目文件夹名称
目录 1.修改之前一定要先备份 2.修改项目的名称 3.修改整个解决方案的名称 1.修改之前一定要先备份 修改失败了,没有备份就得炸裂,一定要切记 2.修改项目的名称 右键项目- >属性 - & ...
- 修改value_Python | 快速修改或命名N个文件夹名称,你会吗?
#欢迎交流:shuilinggan@163.com# 工作中,经常会遇到需要修改或新建很多文件的文件命,是一件重复且头疼的事情,下面一组Python代码,轻松教你快速实现! 程序一:根据 ...
- php循环建立新的文件根据文件名移动文件到指定文件夹修改文件名称
写一个php文件放到你想要批量处理的文件目录下,运行文件即可完成 注意:确认你的文件名是不是时间戳,还有文件里的php文件,要加上判断!不要误删了! <?php set_time_limit(0 ...
- bat 等待输入_bat-批量修改文件或者文件夹名称
Part 1: 获取原有文件和文件夹名称 新建一个TXT文本,在其中输入以下代码 修改文件后缀名为bat 将该文件夹放置于需要修改的文件所属文件夹内 双击,生成Name.txt 代码如下 dir /b ...
- sudo修改文件夹名字_【转载】MAC系统修改帐号短名和个人文件夹名称
根据"系统偏好设置"的"用户"面板中的定义,Mac OS X 中的每个用户都拥有一个全"名称"和一个"短名称".短名称最 ...
- 计算机用户文件夹怎么改名称,win10修改用户名文件夹方法_win10怎么改用户文件夹名称-win7之家...
我们都知道,在win10系统中,用户文件夹通常都是放置在系统中,能够方便用户进行查找,可是近日有些用户总觉得自己电脑中的用户文件夹名称很是普遍,因此就想要进行修改,那么win10怎么改用户文件夹名称呢 ...
- (win10家庭版)修改C盘Users目录下文件夹名称
第一次发博客,写的不好请多多包涵~ 由于本人C:\Users目录下文件夹名称为中文,导致许多软件在安装运行上出现问题,哎~ 1.开启管理员账户 win键+r 输入 cmd 打开黑窗口输入: net u ...
- 教你高效修改文件夹名称,将首写字母改为大写
怎么处理文件,比如快速修改文件夹名称,将首写字母改为大写?不知道如何操作的宝贝们,下面请随小编一起来试试吧,希望能给大家带来帮助. 所需工具 一台电脑 文件夹素材若干 操作步骤 在处理之前,最好将需要 ...
- 织梦php模板在哪个文件夹,织梦模板如何修改默认templets模板文件夹名称的方法...
这篇文章主要为大家详细介绍了织梦模板如何修改默认templets模板文件夹名称的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,有需要的朋友可以收藏方便以后借鉴. 织梦系统的保存模板的默认目录 ...
最新文章
- Linux那些事儿 之 戏说USB(25)设备的生命线(八)
- 增量备份和差异备份的区别|什么是增量差异备份
- FP与IP作为两种编程范型的解决问题思路及其适用领域分析
- desc excel 公式_Excel小技巧之Power Pivot Generate函数、高级DAX函数与常用筛选器函数...
- C语言 学生管理系统
- python 飞机大战小游戏
- 线程池 Executors2
- php 工厂静态类,静态工厂模式(Static Factory)
- 论文浅尝 | 从知识图谱流中学习时序规则
- PyTorch之Sequential
- 让你的git bash更好看更实用
- Linux学习之Vim使用
- 使用函数 imnoise 对图像添加噪声
- python修改pdf文件
- JS自动弹出广告窗口
- 使用docker搭建web服务器,提示无法访问此网站,怎么解决
- 2018最新Python视频教程
- IDEA必备插件系列 - Key Promoter X(快捷键使用提示)
- python安装第三方库错误No matching distribution found for cfg
- JS利用Canvas实现图片等比例裁剪、压缩
热门文章
- PTA题目 猜数字游戏
- 腾讯云cos部署静态网站
- 图片链接转base64编码
- OPPO 设备报错 android.content.res.AssetManager.finalize() timed out after 120 seconds
- 4K如此成熟,8K开始布局,8K视频质量测试,对硬件要求更高!欢迎交流8K
- 1046-最小时间差
- URL文件创建方式_艾孜尔江撰
- ABAP OpenSQL使用索引(HINTS)的参考NOTE记录
- jmeter性能测试快速入门
- 大页内存(HugePages)在通用程序优化中的应用