1 // boost/filesystem/directory.hpp ------------------------------------------//
3 // Copyright © 2002, 2003 Beman Dawes
4 // Copyright © 2002 Jan Langer
5 // Copyright © 2001 Dietmar Kühl
7 // Use, modification, and distribution is subject to the Boost Software
8 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
9 // at http://www.boost.org/LICENSE_1_0.txt)
11 // See library home page at http://www.boost.org/libs/filesystem
13 //----------------------------------------------------------------------------//
15 #ifndef BOOST_FILESYSTEM_DIRECTORY_HPP
16 #define BOOST_FILESYSTEM_DIRECTORY_HPP
18 #include <boost/filesystem/path.hpp> // includes <boost/filesystem/config.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/iterator.hpp>
21 #include <boost/cstdint.hpp>
26 #include <boost/config/abi_prefix.hpp> // must be the last header
28 # ifdef BOOST_NO_STDC_NAMESPACE
29 namespace std { using ::time_t; }
32 //----------------------------------------------------------------------------//
39 // query functions ---------------------------------------------------------//
41 BOOST_FILESYSTEM_DECL bool exists( const path & ph );
42 BOOST_FILESYSTEM_DECL bool symbolic_link_exists( const path & ph );
43 BOOST_FILESYSTEM_DECL bool is_directory( const path & ph );
45 // VC++ 7.0 and earlier has a serious namespace bug that causes a clash
46 // between boost::filesystem::is_empty and the unrelated type trait
47 // boost::is_empty. The workaround for those who must use broken versions
48 // of VC++ is to use the function _is_empty. All others should use the
49 // correct is_empty name.
50 BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph ); // deprecated
52 # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300
53 inline bool is_empty( const path & ph ) { return _is_empty( ph ); }
56 BOOST_FILESYSTEM_DECL bool equivalent( const path & ph1, const path & ph2 );
57 BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph );
58 BOOST_FILESYSTEM_DECL std::time_t last_write_time( const path & ph );
59 BOOST_FILESYSTEM_DECL void last_write_time( const path & ph, const std::time_t new_time );
61 // operations --------------------------------------------------------------//
63 BOOST_FILESYSTEM_DECL bool create_directory( const path & directory_ph );
65 BOOST_FILESYSTEM_DECL bool remove( const path & ph );
66 BOOST_FILESYSTEM_DECL unsigned long remove_all( const path & ph );
68 BOOST_FILESYSTEM_DECL void rename( const path & from_path,
69 const path & to_path );
71 BOOST_FILESYSTEM_DECL void copy_file( const path & from_file_ph,
72 const path & to_file_ph );
74 BOOST_FILESYSTEM_DECL path current_path();
75 BOOST_FILESYSTEM_DECL const path & initial_path();
77 BOOST_FILESYSTEM_DECL path system_complete( const path & ph );
78 BOOST_FILESYSTEM_DECL path complete( const path & ph, const path & base = initial_path() );
80 // test helper -------------------------------------------------------------//
82 // not part of the documented interface because false positives are possible;
83 // there is no law that says that an OS that has large stat.st_size
84 // actually supports large file sizes.
85 BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
88 // directory_iterator helpers ----------------------------------------------//
89 // forwarding functions avoid need for BOOST_FILESYSTEM_DECL for class
90 // directory_iterator, and so avoid iterator_facade DLL template problems
94 // shared_ptr provides shallow-copy semantics required for InputIterators
95 typedef boost::shared_ptr< dir_itr_imp > dir_itr_imp_ptr;
96 BOOST_FILESYSTEM_DECL void dir_itr_init( dir_itr_imp_ptr & m_imp,
97 const path & dir_path );
98 BOOST_FILESYSTEM_DECL path & dir_itr_dereference(
99 const dir_itr_imp_ptr & m_imp );
100 BOOST_FILESYSTEM_DECL void dir_itr_increment( dir_itr_imp_ptr & m_imp );
101 } // namespace detail
103 // directory_iterator ------------------------------------------------------//
105 class directory_iterator
106 : public boost::iterator_facade<
109 boost::single_pass_traversal_tag >
112 directory_iterator(){} // creates the "end" iterator
113 explicit directory_iterator( const path & p )
114 { detail::dir_itr_init( m_imp, p ); }
117 The *r++ requirement doesn't appear to apply to the new single_pass_traversal category
118 Thus I'm leaving the proxy out pending confirmation from the N1477 authors
119 struct path_proxy // allows *r++ to work, as required by 24.1.1
122 explicit path_proxy( const path & p ) : pv(p) {}
123 path operator*() const { return pv; }
126 path_proxy operator++(int)
128 path_proxy pp( m_deref() );
135 detail::dir_itr_imp_ptr m_imp;
136 friend class boost::iterator_core_access;
137 reference dereference() const
138 { return detail::dir_itr_dereference( m_imp ); }
140 { detail::dir_itr_increment( m_imp ); }
141 bool equal( const directory_iterator & rhs ) const
142 { return m_imp == rhs.m_imp; }
144 } // namespace filesystem
148 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
149 #endif // BOOST_FILESYSTEM_DIRECTORY_HPP