summaryrefslogtreecommitdiff
path: root/libs/filesystem/example/mbcopy.cpp
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2013-08-26 08:15:55 -0400
committerAnas Nashif <anas.nashif@intel.com>2013-08-26 08:15:55 -0400
commitbb4dd8289b351fae6b55e303f189127a394a1edd (patch)
tree77c9c35a31b1459dd7988c2448e797d142530c41 /libs/filesystem/example/mbcopy.cpp
parent1a78a62555be32868418fe52f8e330c9d0f95d5a (diff)
downloadboost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.gz
boost-bb4dd8289b351fae6b55e303f189127a394a1edd.tar.bz2
boost-bb4dd8289b351fae6b55e303f189127a394a1edd.zip
Imported Upstream version 1.51.0upstream/1.51.0
Diffstat (limited to 'libs/filesystem/example/mbcopy.cpp')
-rw-r--r--libs/filesystem/example/mbcopy.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/libs/filesystem/example/mbcopy.cpp b/libs/filesystem/example/mbcopy.cpp
new file mode 100644
index 0000000000..2b1f603823
--- /dev/null
+++ b/libs/filesystem/example/mbcopy.cpp
@@ -0,0 +1,90 @@
+// Boost.Filesystem mbcopy.cpp ---------------------------------------------//
+
+// Copyright Beman Dawes 2005
+
+// Use, modification, and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// Copy the files in a directory, using mbpath to represent the new file names
+// See http://../doc/path.htm#mbpath for more information
+
+// See deprecated_test for tests of deprecated features
+#define BOOST_FILESYSTEM_NO_DEPRECATED
+
+#include <boost/filesystem/config.hpp>
+# ifdef BOOST_FILESYSTEM_NARROW_ONLY
+# error This compiler or standard library does not support wide-character strings or paths
+# endif
+
+#include "mbpath.hpp"
+#include <iostream>
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/fstream.hpp>
+#include "../src/utf8_codecvt_facet.hpp"
+
+namespace fs = boost::filesystem;
+
+namespace
+{
+ // we can't use boost::filesystem::copy_file() because the argument types
+ // differ, so provide a not-very-smart replacement.
+
+ void copy_file( const fs::wpath & from, const user::mbpath & to )
+ {
+ fs::ifstream from_file( from, std::ios_base::in | std::ios_base::binary );
+ if ( !from_file ) { std::cout << "input open failed\n"; return; }
+
+ fs::ofstream to_file( to, std::ios_base::out | std::ios_base::binary );
+ if ( !to_file ) { std::cout << "output open failed\n"; return; }
+
+ char c;
+ while ( from_file.get(c) )
+ {
+ to_file.put(c);
+ if ( to_file.fail() ) { std::cout << "write error\n"; return; }
+ }
+
+ if ( !from_file.eof() ) { std::cout << "read error\n"; }
+ }
+}
+
+int main( int argc, char * argv[] )
+{
+ if ( argc != 2 )
+ {
+ std::cout << "Copy files in the current directory to a target directory\n"
+ << "Usage: mbcopy <target-dir>\n";
+ return 1;
+ }
+
+ // For encoding, use Boost UTF-8 codecvt
+ std::locale global_loc = std::locale();
+ std::locale loc( global_loc, new fs::detail::utf8_codecvt_facet );
+ user::mbpath_traits::imbue( loc );
+
+ std::string target_string( argv[1] );
+ user::mbpath target_dir( user::mbpath_traits::to_internal( target_string ) );
+
+ if ( !fs::is_directory( target_dir ) )
+ {
+ std::cout << "Error: " << argv[1] << " is not a directory\n";
+ return 1;
+ }
+
+ for ( fs::wdirectory_iterator it( L"." );
+ it != fs::wdirectory_iterator(); ++it )
+ {
+ if ( fs::is_regular_file(it->status()) )
+ {
+ copy_file( *it, target_dir / it->path().filename() );
+ }
+ }
+
+ return 0;
+}
+
+
+
+
+