|
本帖最后由 zmrghy 于 2022-5-23 20:45 编辑
全部注释掉,留个空函数,还是有错。
- #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 个 ==========
本帖最后由 freehawkzk 于 2022-5-24 08:57 编辑
没记错的话filesystem是很新的C++标准才支持的,
试试在属性->C/C++->语言->C++语言标准设置成最新试试。
实在不行,换VS2022.
|
上一篇: 读取汉字,再输出,变成乱码下一篇: 关于SQL SERVER
|