| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1770 人关注过本帖, 1 人收藏
标题:求助,字符串编辑,修改文件名
只看楼主 加入收藏
追梦人zmrghy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:406
专家分:190
注 册:2021-4-9
收藏
得分:0 
回复 9楼 rjsp
全部注释掉,只留个空函数,还是有错

程序代码:
#include <iostream>
#include <filesystem>
#include <algorithm>
using namespace std;

bool ReduceFileName(const std::filesystem::path& path)
{
    //auto make_name_name = [](const std::wstring& filename)
    //{
    //    size_t a = filename.find(L':');
    //    if (a != std::wstring::npos)
    //    {
    //        a = filename.find_first_not_of(L"\t\n\v\f\r ", a + 1);
    //        size_t b = filename.find_first_of(L"((", a);
    //        b = filename.find_last_not_of(L"\t\n\v\f\r ", b - 1);
    //        return filename.substr(a, b + 1 - a);
    //    }
    //    return filename;
    //};

    //using namespace std::filesystem;
    //try
    //{
    //    for (auto& entry : directory_iterator(path))
    //    {
    //        if (entry.is_regular_file()) // 只处理常规文件
    //        {
    //            auto ext = entry.path().extension().generic_wstring(); // 扩展名
    //            std::for_each(begin(ext), end(ext), [](auto& c) {if (c >= L'A'&&c <= L'Z') c += L'a' - L'A'; }); // 扩展名转化成小写
    //            if (ext == L".mp4")
    //            {
    //                const auto& old_name = entry.path().stem().generic_wstring();
    //                const auto& new_name = make_name_name(old_name);
    //                if (old_name != new_name)
    //                {
    //                    wcout << old_name << L" -> " << new_name;

    //                    auto new_path = entry.path().parent_path() / (new_name + L".mp4");
    //                    if (exists(new_path)) // 新文件名已经存在
    //                    {
    //                        wcout << L" --- [failed] 文件已存在";
    //                    }
    //                    else
    //                    {
    //                        std::error_code ec;
    //                        rename(entry, new_path, ec);
    //                        if (ec)
    //                            cout << " --- [failed] " << ec.message();
    //                    }

    //                    wcout << L'\n';
    //                }
    //            }
    //        }
    //    }
    //}
    //catch (const std::exception& e)
    //{
    //    cout << "[failed] " << e.what() << '\n';
    //    return false;
    //}
    return true;
}

int main(void)
{
    wcout.imbue(std::locale(std::locale(), "", std::locale::ctype));
    ReduceFileName(u8R"(C:\Users\Administrator\Desktop\[WPF]JJDown\Download\)"); // 使用 Unicode 可避免GBK认字不全
}


>------ 已启动生成: 项目: test3, 配置: Debug Win32 ------
1>  test3.cpp
1>test3.cpp(6): error C3083: “filesystem”:“::”左侧的符号必须是一种类型
1>test3.cpp(6): error C2039: “path”: 不是“std”的成员
1>  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\filesystem(26): note: 参见“std”的声明
1>test3.cpp(6): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>test3.cpp(6): error C2143: 语法错误: 缺少“,”(在“&”的前面)
1>test3.cpp(68): error C2664: “bool ReduceFileName(const int)”: 无法将参数 1 从“const char [53]”转换为“const int”
1>  test3.cpp(68): note: 没有使该转换得以执行的上下文
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
2022-05-23 20:26
追梦人zmrghy
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:406
专家分:190
注 册:2021-4-9
收藏
得分:0 
回复 9楼 rjsp
std::filesystem
C++17 VS2019才能使用对吗???
VS2015,无法使用对吗???
2022-05-23 21:27
快速回复:求助,字符串编辑,修改文件名
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025246 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved