| 
 | 
 
 本帖最后由 aeszyl 于 2024-12-24 16:02 编辑  
 
  c++代码嵌入是火山中文编程的灵魂,这几天一直研究这方面的知识,先用AI(我用的是:文心快码)根据要求输出c++代码,再转成嵌入式代码。下面代码中的正则表达式,稍做修改,可以实现各种文件批量重命名功能。 
- <火山程序 类型 = "通常" 版本 = 1 />
 
  
- 包 火山.程序
 
  
- 类 启动类 <公开 基础类 = 窗口程序类>
 
 - {
 
 -     方法 启动方法 <公开 类型 = 整数>
 
 -     {
 
 -         文件批量更名 ()
 
 -         返回 (1)
 
 -     }
 
  
-     方法 文件批量更名 <公开 静态 @视窗.外部头文件 = "<iostream>\r\n<filesystem>\r\n<string>\r\n<regex>"
 
 -             @视窗.附加编译参数 = "cpp: /std:c++17">
 
 -     {
 
 -         // 文件目录=当前目录
 
 -         @ std::filesystem::path currentDir = std::filesystem::current_path();
 
 -         // 遍历当前目录中的所有文件
 
 -         @ for (const auto& entry : std::filesystem::directory_iterator(currentDir)) {
 
 -         @ if (std::filesystem::is_regular_file(entry.status())) {
 
 -         @ std::string filename = entry.path().filename().string();
 
 -         // 使用正则表达式匹配文件名(名称1-名称2.*)
 
 -         @ std::regex pattern(R"(([^-]+)-([^-]+)(\..+))");
 
 -         @ std::smatch match;
 
 -         @ if (std::regex_match(filename, match, pattern)) {
 
 -         @ std::string name1 = match[1].str();
 
 -         @ std::string name2 = match[2].str();
 
 -         @ std::string name3 = match[3].str();
 
 -         // 构建新文件名(名称2-名称1.*)
 
 -         @ std::string newName = name2 + "-" + name1 +  name3;
 
 -         @ std::cout << "Renaming " << filename << " to " << newName << std::endl;
 
 -         // 批量重命名文件
 
 -         @ std::filesystem::rename(entry.path(), entry.path().parent_path() / newName);
 
 -         @ }
 
 -         @ }
 
 -         @ }
 
 -     }
 
 - }
 
 
  复制代码 
 
 
 |   
 
 
 
 |