|
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完是唬人的呀!!!
- #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 )
- {
- setlocale( LC_CTYPE, "" );
- ReduceFileName( u8R"(C:\Users\Administrator\Desktop\[WPF]JJDown\Download\)" ); // 使用 Unicode 可避免GBK认字不全
- }
复制代码
代码文件
main.rar
(1016 Bytes, 下载次数: 0)
|
上一篇: DeviceIoControl给硬盘分区,请教~下一篇: 谁能告诉我,这到底是为什么,同样代码,结果却不同
|