early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,25 @@
# Boost Filesystem Library Example Jamfile
# (C) Copyright Vladimir Prus 2003
# Distributed under the Boost Software License, Version 1.0.
# See www.boost.org/LICENSE_1_0.txt
# Library home page: http://www.boost.org/libs/filesystem
project
: requirements
<library>/boost/filesystem//boost_filesystem
<link>static
;
exe tut0 : tut0.cpp ;
exe tut1 : tut1.cpp ;
exe tut2 : tut2.cpp ;
exe tut3 : tut3.cpp : <cxxstd>11 ;
exe tut4 : tut4.cpp : <cxxstd>11 ;
exe tut5 : tut5.cpp ;
exe path_info : path_info.cpp : <cxxstd>11 ;
exe file_status : file_status.cpp ;
exe file_size : file_size.cpp ;
exe directory_symlink_parent_resolution : directory_symlink_parent_resolution.cpp ;

View File

@@ -0,0 +1,42 @@
// directory_symlink_parent_resolution.cpp -------------------------------------------//
// Copyright Beman Dawes 2015
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/filesystem.hpp>
#include <boost/filesystem/string_file.hpp>
#include <boost/detail/lightweight_main.hpp>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using namespace boost::filesystem;
int cpp_main(int argc, char* argv[])
{
#ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API" << endl;
#else
cout << "BOOST_POSIX_API" << endl;
#endif
path test_dir(current_path() / "dspr_demo");
remove_all(test_dir);
create_directories(test_dir / "a/c/d");
current_path(test_dir / "a");
create_directory_symlink("c/d", "b");
save_string_file("name.txt", "Windows");
save_string_file("c/name.txt", "POSIX");
current_path(test_dir);
std::string s;
load_string_file("a/b/../name.txt", s);
cout << s << endl;
return 0;
}

View File

@@ -0,0 +1,200 @@
// error_demo.cpp --------------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// //
// The purpose of this program is to demonstrate how error reporting works. //
// //
//--------------------------------------------------------------------------------------//
#include <boost/filesystem.hpp>
#include <boost/system/system_error.hpp>
#include <iostream>
using std::cout;
using boost::filesystem::path;
using boost::filesystem::filesystem_error;
using boost::system::error_code;
using boost::system::system_error;
namespace fs = boost::filesystem;
namespace {
void report_system_error(const system_error& ex)
{
cout << " threw system_error:\n"
<< " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n';
}
void report_filesystem_error(const system_error& ex)
{
cout << " threw filesystem_error exception:\n"
<< " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n';
}
void report_status(fs::file_status s)
{
cout << " file_status::type() is ";
switch (s.type())
{
case fs::status_error:
cout << "status_error\n";
break;
case fs::file_not_found:
cout << "file_not_found\n";
break;
case fs::regular_file:
cout << "regular_file\n";
break;
case fs::directory_file:
cout << "directory_file\n";
break;
case fs::symlink_file:
cout << "symlink_file\n";
break;
case fs::block_file:
cout << "block_file\n";
break;
case fs::character_file:
cout << "character_file\n";
break;
case fs::fifo_file:
cout << "fifo_file\n";
break;
case fs::socket_file:
cout << "socket_file\n";
break;
case fs::type_unknown:
cout << "type_unknown\n";
break;
default:
cout << "not a valid enumeration constant\n";
}
}
void report_error_code(const error_code& ec)
{
cout << " ec:\n"
<< " value() is " << ec.value() << '\n'
<< " category().name() is " << ec.category().name() << '\n'
<< " message() is " << ec.message() << '\n';
}
bool threw_exception;
} // namespace
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: error_demo path\n";
return 1;
}
error_code ec;
//// construct path - no error_code
//try { path p1(argv[1]); }
//catch (const system_error& ex)
//{
// cout << "construct path without error_code";
// report_system_error(ex);
//}
//// construct path - with error_code
path p(argv[1]);
fs::file_status s;
bool b(false);
fs::directory_iterator di;
// get status - no error_code
cout << "\nstatus(\"" << p.string() << "\");\n";
threw_exception = false;
try
{
s = fs::status(p);
}
catch (const system_error& ex)
{
report_filesystem_error(ex);
threw_exception = true;
}
if (!threw_exception)
cout << " Did not throw exception\n";
report_status(s);
// get status - with error_code
cout << "\nstatus(\"" << p.string() << "\", ec);\n";
s = fs::status(p, ec);
report_status(s);
report_error_code(ec);
// query existence - no error_code
cout << "\nexists(\"" << p.string() << "\");\n";
threw_exception = false;
try
{
b = fs::exists(p);
}
catch (const system_error& ex)
{
report_filesystem_error(ex);
threw_exception = true;
}
if (!threw_exception)
{
cout << " Did not throw exception\n"
<< " Returns: " << (b ? "true" : "false") << '\n';
}
// query existence - with error_code
// directory_iterator - no error_code
cout << "\ndirectory_iterator(\"" << p.string() << "\");\n";
threw_exception = false;
try
{
di = fs::directory_iterator(p);
}
catch (const system_error& ex)
{
report_filesystem_error(ex);
threw_exception = true;
}
if (!threw_exception)
{
cout << " Did not throw exception\n"
<< (di == fs::directory_iterator() ? " Equal" : " Not equal")
<< " to the end iterator\n";
}
// directory_iterator - with error_code
cout << "\ndirectory_iterator(\"" << p.string() << "\", ec);\n";
di = fs::directory_iterator(p, ec);
cout << (di == fs::directory_iterator() ? " Equal" : " Not equal")
<< " to the end iterator\n";
report_error_code(ec);
return 0;
}

View File

@@ -0,0 +1,44 @@
// file_size program -------------------------------------------------------//
// Copyright Beman Dawes, 2004
// 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)
// See http://www.boost.org/libs/filesystem for documentation.
#include <boost/filesystem/operations.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cout << "Usage: file_size path\n";
return 1;
}
std::cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n';
fs::path p(argv[1]);
if (!fs::exists(p))
{
std::cout << "not found: " << argv[1] << std::endl;
return 1;
}
if (!fs::is_regular(p))
{
std::cout << "not a regular file: " << argv[1] << std::endl;
return 1;
}
std::cout << "size of " << argv[1] << " is " << fs::file_size(p)
<< std::endl;
return 0;
}

View File

@@ -0,0 +1,116 @@
// status.cpp ------------------------------------------------------------------------//
// Copyright Beman Dawes 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/config.hpp>
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
#include <boost/detail/lightweight_main.hpp>
using std::cout;
using std::endl;
using namespace boost::filesystem;
namespace {
path p;
void print_boost_macros()
{
std::cout << "Boost "
<< BOOST_VERSION / 100000 << '.'
<< BOOST_VERSION / 100 % 1000 << '.'
<< BOOST_VERSION % 100 << ", "
#ifndef _WIN64
<< BOOST_COMPILER << ", "
#else
<< BOOST_COMPILER << " with _WIN64 defined, "
#endif
<< BOOST_STDLIB << ", "
<< BOOST_PLATFORM
<< std::endl;
}
const char* file_type_tab[] = { "status_error", "file_not_found", "regular_file", "directory_file",
"symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
"type_unknown" };
const char* file_type_c_str(enum file_type t)
{
return file_type_tab[t];
}
void show_status(file_status s, boost::system::error_code ec)
{
boost::system::error_condition econd;
if (ec)
{
econd = ec.default_error_condition();
cout << "sets ec to indicate an error:\n"
<< " ec.value() is " << ec.value() << '\n'
<< " ec.message() is \"" << ec.message() << "\"\n"
<< " ec.default_error_condition().value() is " << econd.value() << '\n'
<< " ec.default_error_condition().message() is \"" << econd.message() << "\"\n";
}
else
cout << "clears ec.\n";
cout << "s.type() is " << s.type()
<< ", which is defined as \"" << file_type_c_str(s.type()) << "\"\n";
cout << "exists(s) is " << (exists(s) ? "true" : "false") << "\n";
cout << "status_known(s) is " << (status_known(s) ? "true" : "false") << "\n";
cout << "is_regular_file(s) is " << (is_regular_file(s) ? "true" : "false") << "\n";
cout << "is_directory(s) is " << (is_directory(s) ? "true" : "false") << "\n";
cout << "is_other(s) is " << (is_other(s) ? "true" : "false") << "\n";
cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n";
}
void try_exists()
{
cout << "\nexists(" << p << ") ";
try
{
bool result = exists(p);
cout << "is " << (result ? "true" : "false") << "\n";
}
catch (const filesystem_error& ex)
{
cout << "throws a filesystem_error exception: " << ex.what() << "\n";
}
}
} // namespace
int cpp_main(int argc, char* argv[])
{
print_boost_macros();
if (argc < 2)
{
std::cout << "Usage: file_status <path>\n";
p = argv[0];
}
else
p = argv[1];
boost::system::error_code ec;
file_status s = status(p, ec);
cout << "\nfile_status s = status(" << p << ", ec) ";
show_status(s, ec);
s = symlink_status(p, ec);
cout << "\nfile_status s = symlink_status(" << p << ", ec) ";
show_status(s, ec);
try_exists();
return 0;
}

View File

@@ -0,0 +1,100 @@
// 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";
}
}
} // namespace
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;
}

View File

@@ -0,0 +1,78 @@
// Boost.Filesystem mbpath.cpp ---------------------------------------------//
// (c) 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)
// See Boost.Filesystem home page at http://www.boost.org/libs/filesystem
#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 <boost/system/system_error.hpp>
#include <boost/scoped_array.hpp>
namespace fs = boost::filesystem;
namespace {
// ISO C calls this "the locale-specific native environment":
std::locale loc("");
const std::codecvt< wchar_t, char, std::mbstate_t >*
cvt(&std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc));
} // namespace
namespace user {
mbpath_traits::external_string_type
mbpath_traits::to_external(const mbpath& ph, const internal_string_type& src)
{
std::size_t work_size(cvt->max_length() * (src.size() + 1));
boost::scoped_array< char > work(new char[work_size]);
std::mbstate_t state;
const internal_string_type::value_type* from_next;
external_string_type::value_type* to_next;
if (cvt->out(
state, src.c_str(), src.c_str() + src.size(), from_next, work.get(),
work.get() + work_size, to_next) != std::codecvt_base::ok)
boost::throw_exception< fs::basic_filesystem_error< mbpath > >(
fs::basic_filesystem_error< mbpath >(
"user::mbpath::to_external conversion error",
ph, boost::system::error_code(EINVAL, boost::system::errno_ecat)));
*to_next = '\0';
return external_string_type(work.get());
}
mbpath_traits::internal_string_type
mbpath_traits::to_internal(const external_string_type& src)
{
std::size_t work_size(src.size() + 1);
boost::scoped_array< wchar_t > work(new wchar_t[work_size]);
std::mbstate_t state;
const external_string_type::value_type* from_next;
internal_string_type::value_type* to_next;
if (cvt->in(
state, src.c_str(), src.c_str() + src.size(), from_next, work.get(),
work.get() + work_size, to_next) != std::codecvt_base::ok)
boost::throw_exception< fs::basic_filesystem_error< mbpath > >(
fs::basic_filesystem_error< mbpath >(
"user::mbpath::to_internal conversion error",
boost::system::error_code(EINVAL, boost::system::errno_ecat)));
*to_next = L'\0';
return internal_string_type(work.get());
}
void mbpath_traits::imbue(const std::locale& new_loc)
{
loc = new_loc;
cvt = &std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc);
}
} // namespace user

View File

@@ -0,0 +1,47 @@
// Boost.Filesystem mbpath.hpp ---------------------------------------------//
// 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)
// Encodes wide character paths as MBCS
// See http://../doc/path.htm#mbpath for more information
#include <boost/filesystem/path.hpp>
#include <cwchar> // for std::mbstate_t
#include <string>
#include <locale>
namespace user {
struct mbpath_traits;
typedef boost::filesystem::basic_path< std::wstring, mbpath_traits > mbpath;
struct mbpath_traits
{
typedef std::wstring internal_string_type;
typedef std::string external_string_type;
static external_string_type to_external(const mbpath& ph, const internal_string_type& src);
static internal_string_type to_internal(const external_string_type& src);
static void imbue(const std::locale& loc);
};
} // namespace user
namespace boost {
namespace filesystem {
template<>
struct is_basic_path< user::mbpath >
{
static const bool value = true;
};
} // namespace filesystem
} // namespace boost

View File

@@ -0,0 +1,86 @@
// path_info.cpp ---------------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
const char* say_what(bool b)
{
return b ? "true" : "false";
}
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: path_info path-element [path-element...]\n"
"Composes a path via operator/= from one or more path-element arguments\n"
"Example: path_info foo/bar baz\n"
#ifdef BOOST_POSIX_API
" would report info about the composed path foo/bar/baz\n";
#else // BOOST_WINDOWS_API
" would report info about the composed path foo/bar\\baz\n";
#endif
return 1;
}
path p;
for (; argc > 1; --argc, ++argv)
p /= argv[1]; // compose path p from the command line arguments
cout << "\ncomposed path:\n";
cout << " operator<<()---------: " << p << "\n";
cout << " make_preferred()-----: " << p.make_preferred() << "\n";
cout << "\nelements:\n";
for (auto element : p)
cout << " " << element << '\n';
cout << "\nobservers, native format:" << endl;
#ifdef BOOST_POSIX_API
cout << " native()-------------: " << p.native() << endl;
cout << " c_str()--------------: " << p.c_str() << endl;
#else // BOOST_WINDOWS_API
wcout << L" native()-------------: " << p.native() << endl;
wcout << L" c_str()--------------: " << p.c_str() << endl;
#endif
cout << " string()-------------: " << p.string() << endl;
wcout << L" wstring()------------: " << p.wstring() << endl;
cout << "\nobservers, generic format:\n";
cout << " generic_string()-----: " << p.generic_string() << endl;
wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
cout << "\ndecomposition:\n";
cout << " root_name()----------: " << p.root_name() << '\n';
cout << " root_directory()-----: " << p.root_directory() << '\n';
cout << " root_path()----------: " << p.root_path() << '\n';
cout << " relative_path()------: " << p.relative_path() << '\n';
cout << " parent_path()--------: " << p.parent_path() << '\n';
cout << " filename()-----------: " << p.filename() << '\n';
cout << " stem()---------------: " << p.stem() << '\n';
cout << " extension()----------: " << p.extension() << '\n';
cout << "\nquery:\n";
cout << " empty()--------------: " << say_what(p.empty()) << '\n';
cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n';
cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n';
cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n';
cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
return 0;
}

View File

@@ -0,0 +1,90 @@
// simple_ls program -------------------------------------------------------//
// Copyright Jeff Garland and Beman Dawes, 2002
// 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)
// See http://www.boost.org/libs/filesystem for documentation.
// As an example program, we don't want to use any deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/directory.hpp>
#include <boost/filesystem/path.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main(int argc, char* argv[])
{
fs::path p(fs::current_path());
if (argc > 1)
p = fs::system_complete(argv[1]);
else
std::cout << "\nusage: simple_ls [path]" << std::endl;
unsigned long file_count = 0;
unsigned long dir_count = 0;
unsigned long other_count = 0;
unsigned long err_count = 0;
if (!fs::exists(p))
{
std::cout << "\nNot found: " << p << std::endl;
return 1;
}
if (fs::is_directory(p))
{
std::cout << "\nIn directory: " << p << "\n\n";
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_itr(p);
dir_itr != end_iter;
++dir_itr)
{
try
{
if (fs::is_directory(dir_itr->status()))
{
++dir_count;
std::cout << dir_itr->path().filename() << " [directory]\n";
}
else if (fs::is_regular_file(dir_itr->status()))
{
++file_count;
std::cout << dir_itr->path().filename() << "\n";
}
else
{
++other_count;
std::cout << dir_itr->path().filename() << " [other]\n";
}
}
catch (const std::exception& ex)
{
++err_count;
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
}
}
std::cout << "\n"
<< file_count << " files\n"
<< dir_count << " directories\n"
<< other_count << " others\n"
<< err_count << " errors\n";
}
else // must be a file
{
std::cout << "\nFound: " << p << "\n";
}
return 0;
}

View File

@@ -0,0 +1,31 @@
// filesystem example stems.cpp ------------------------------------------------------//
// Copyright Beman Dawes 2011
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/filesystem.hpp>
#include <iostream>
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: stems <path>\n";
return 1;
}
boost::filesystem::path p(argv[1]), name(p.filename());
for (;;)
{
std::cout << "filename " << name << " has stem " << name.stem()
<< " and extension " << name.extension() << "\n";
if (name.stem().empty() || name.extension().empty())
return 0;
name = name.stem();
}
}

View File

@@ -0,0 +1,39 @@
// Example use of Microsoft TCHAR ----------------------------------------------------//
// Copyright Beman Dawes 2008
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <string>
#include <cassert>
#include <windows.h>
#include <winnt.h>
namespace fs = boost::filesystem;
typedef std::basic_string< TCHAR > tstring;
void func(fs::path const& p)
{
assert(fs::exists(p));
}
int main()
{
// get a path that is known to exist
fs::path cp = fs::current_path();
// demo: get tstring from the path
tstring cp_as_tstring = cp.string< tstring >();
// demo: pass tstring to filesystem function taking path
assert(fs::exists(cp_as_tstring));
// demo: pass tstring to user function taking path
func(cp_as_tstring);
return 0;
}

View File

@@ -0,0 +1,24 @@
// filesystem tut0.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut0 path\n";
return 1;
}
std::cout << argv[1] << '\n';
return 0;
}

View File

@@ -0,0 +1,24 @@
// filesystem tut1.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut1 path\n";
return 1;
}
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0;
}

View File

@@ -0,0 +1,39 @@
// filesystem tut2.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: tut2 path\n";
return 1;
}
path p(argv[1]); // avoid repeated path construction below
if (exists(p)) // does path p actually exist?
{
if (is_regular_file(p)) // is path p a regular file?
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p)) // is path p a directory?
cout << p << " is a directory\n";
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
return 0;
}

View File

@@ -0,0 +1,53 @@
// filesystem tut3.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: tut3 path\n";
return 1;
}
path p(argv[1]);
try
{
if (exists(p))
{
if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
for (directory_entry const& x : directory_iterator(p))
cout << " " << x.path() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
}
catch (filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
}

View File

@@ -0,0 +1,62 @@
// filesystem tut4.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
cout << "Usage: tut4 path\n";
return 1;
}
path p(argv[1]);
try
{
if (exists(p))
{
if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
std::vector< path > v;
for (auto&& x : directory_iterator(p))
v.push_back(x.path());
std::sort(v.begin(), v.end());
for (auto&& x : v)
cout << " " << x.filename() << '\n';
}
else
cout << p << " exists, but is not a regular file or directory\n";
}
else
cout << p << " does not exist\n";
}
catch (filesystem_error& ex)
{
cout << ex.what() << '\n';
}
return 0;
}

View File

@@ -0,0 +1,69 @@
// filesystem tut5.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <boost/filesystem/fstream.hpp>
#include <string>
#include <list>
namespace fs = boost::filesystem;
int main()
{
// \u263A is "Unicode WHITE SMILING FACE = have a nice day!"
std::string narrow_string("smile2");
std::wstring wide_string(L"smile2\u263A");
std::list< char > narrow_list;
narrow_list.push_back('s');
narrow_list.push_back('m');
narrow_list.push_back('i');
narrow_list.push_back('l');
narrow_list.push_back('e');
narrow_list.push_back('3');
std::list< wchar_t > wide_list;
wide_list.push_back(L's');
wide_list.push_back(L'm');
wide_list.push_back(L'i');
wide_list.push_back(L'l');
wide_list.push_back(L'e');
wide_list.push_back(L'3');
wide_list.push_back(L'\u263A');
{
fs::ofstream f("smile");
}
{
fs::ofstream f(L"smile\u263A");
}
{
fs::ofstream f(narrow_string);
}
{
fs::ofstream f(wide_string);
}
{
fs::ofstream f(narrow_list);
}
{
fs::ofstream f(wide_list);
}
narrow_list.pop_back();
narrow_list.push_back('4');
wide_list.pop_back();
wide_list.pop_back();
wide_list.push_back(L'4');
wide_list.push_back(L'\u263A');
{
fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end()));
}
{
fs::ofstream f(fs::path(wide_list.begin(), wide_list.end()));
}
return 0;
}

View File

@@ -0,0 +1,48 @@
// filesystem tut6a.cpp --------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <exception>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut6a path\n";
return 1;
}
try
{
for (recursive_directory_iterator it(argv[1]);
it != recursive_directory_iterator();
++it)
{
if (it.level() > 1)
it.pop();
else
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
std::cout << it->path() << '\n';
}
}
}
catch (std::exception& ex)
{
std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n';
}
return 0;
}

View File

@@ -0,0 +1,52 @@
// filesystem tut6b.cpp --------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <exception>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut6b path\n";
return 1;
}
try
{
for (recursive_directory_iterator it(argv[1]);
it != recursive_directory_iterator();)
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
std::cout << it->path() << '\n';
try
{
++it;
}
catch (filesystem_error& ex)
{
std::cout << "************* filesystem_error *****************\n";
std::cout << ex.what() << '\n';
}
}
}
catch (std::exception& ex)
{
std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n';
}
return 0;
}

View File

@@ -0,0 +1,39 @@
// filesystem tut6c.cpp --------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <exception>
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
using namespace boost::filesystem;
using namespace boost::system;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut6c path\n";
return 1;
}
error_code ec;
for (recursive_directory_iterator it(argv[1], ec);
it != recursive_directory_iterator();)
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
std::cout << it->path() << '\n';
it.increment(ec);
}
return 0;
}