VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 595|回复: 0

|error: 'filesystem' in namespace 'std' does not name a type

[复制链接]
38_avatar_middle
最佳答案
0 
在线会员 发表于 2022-5-28 01:07:04 | 显示全部楼层 |阅读模式
C:\Users\Administrator\Documents\C++\filerename\main.cpp|6|error: 'filesystem' in namespace 'std' does not name a type|

为什么不支持 std::filerename::path呀

听说,C++17就可以支持 std::filerename::path  了呀。。。

用得是Code::Blocks  20.03,,传说它是支持C++20的呀。。。
不什么,不支持C++17的标准了呀??
把它说地挺牛B。。。。
TMD完是唬人的呀!!!

|error: 'filesystem' in namespace 'std' does not name a type
|error: 'filesystem' in namespace 'std' does not name a type

  1. #include <iostream>
  2. #include <filesystem>
  3. #include <algorithm>
  4. using namespace std;

  5. bool ReduceFileName( const std::filesystem::path& path )
  6. {
  7.     auto make_name_name = []( const std::wstring& filename )
  8.     {
  9.         size_t a = filename.find( L':' );
  10.         if( a != std::wstring::npos )
  11.         {
  12.             a = filename.find_first_not_of( L"\t\n\v\f\r ", a+1 );
  13.             size_t b = filename.find_first_of( L"((", a );
  14.             b = filename.find_last_not_of( L"\t\n\v\f\r ", b-1 );
  15.             return filename.substr( a, b+1-a );
  16.         }
  17.         return filename;
  18.     };

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

  35.                         auto new_path = entry.path().parent_path()/(new_name+L".mp4");
  36.                         if( exists(new_path) ) // 新文件名已经存在
  37.                         {
  38.                             wcout << L" --- [failed] 文件已存在";
  39.                         }
  40.                         else
  41.                         {
  42.                             std::error_code ec;
  43.                             rename( entry, new_path, ec );
  44.                             if( ec )
  45.                                 cout << " --- [failed] " << ec.message();
  46.                         }

  47.                         wcout << L'\n';
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.     }
  53.     catch( const std::exception& e )
  54.     {
  55.         cout << "[failed] " << e.what() << '\n';
  56.         return false;
  57.     }
  58.     return true;
  59. }

  60. int main( void )
  61. {
  62.     setlocale( LC_CTYPE, "" );

  63.     ReduceFileName( u8R"(C:\Users\Administrator\Desktop\[WPF]JJDown\Download\)" ); // 使用 Unicode 可避免GBK认字不全
  64. }
复制代码



代码文件
|error: 'filesystem' in namespace 'std' does not name a type main.rar (1016 Bytes, 下载次数: 0)




上一篇:DeviceIoControl给硬盘分区,请教~
下一篇:谁能告诉我,这到底是为什么,同样代码,结果却不同
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2023-12-1 22:27

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表