1 // windows_attributes ----------------------------------------------------------------//
3 // Copyright Beman Dawes 2010
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 // Library home page: http://www.boost.org/libs/filesystem
10 //--------------------------------------------------------------------------------------//
12 // Useful for debugging status related issues //
14 //--------------------------------------------------------------------------------------//
16 #include <boost/filesystem.hpp>
17 #include <boost/detail/lightweight_main.hpp>
25 namespace fs
= boost::filesystem
;
27 int cpp_main(int argc
, char* argv
[])
29 typedef std::map
< DWORD
, std::string
> decode_type
;
32 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_ARCHIVE
, "FILE_ATTRIBUTE_ARCHIVE"));
33 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_COMPRESSED
, "FILE_ATTRIBUTE_COMPRESSED"));
34 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_DEVICE
, "FILE_ATTRIBUTE_DEVICE"));
35 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_DIRECTORY
, "FILE_ATTRIBUTE_DIRECTORY"));
36 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_ENCRYPTED
, "FILE_ATTRIBUTE_ENCRYPTED"));
37 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_HIDDEN
, "FILE_ATTRIBUTE_HIDDEN"));
38 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"));
39 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_OFFLINE
, "FILE_ATTRIBUTE_OFFLINE"));
40 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_READONLY
, "FILE_ATTRIBUTE_READONLY"));
41 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_REPARSE_POINT
, "FILE_ATTRIBUTE_REPARSE_POINT"));
42 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_SPARSE_FILE
, "FILE_ATTRIBUTE_SPARSE_FILE"));
43 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_SYSTEM
, "FILE_ATTRIBUTE_SYSTEM"));
44 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_TEMPORARY
, "FILE_ATTRIBUTE_TEMPORARY"));
45 table
.insert(make_pair
< DWORD
, std::string
>(FILE_ATTRIBUTE_VIRTUAL
, "FILE_ATTRIBUTE_VIRTUAL"));
49 std::cout
<< "Usage: windows_attributes path\n";
53 // report Win32 ::GetFileAttributesA()
55 DWORD
at(::GetFileAttributesA(argv
[1]));
56 if (at
== INVALID_FILE_ATTRIBUTES
)
58 std::cout
<< "GetFileAttributes(\"" << argv
[1]
59 << "\") returned INVALID_FILE_ATTRIBUTES\n";
63 std::cout
<< "GetFileAttributes(\"" << argv
[1]
67 for (decode_type::iterator it
= table
.begin(); it
!= table
.end(); ++it
)
69 if (!(it
->first
& at
))
74 std::cout
<< it
->second
;
77 std::cout
<< std::endl
;
80 std::cout
<< "plus unknown attributes " << at
<< std::endl
;
82 // report Boost Filesystem file_type
84 fs::file_status stat
= fs::status(argv
[1]);
92 // the following may not apply to some operating systems or file systems
98 "reparse_file", // Windows: FILE_ATTRIBUTE_REPARSE_POINT that is not a symlink
99 "type_unknown" // file does exist", but isn't one of the above types or
100 // we don't have strong enough permission to find its type
103 std::cout
<< "boost::filesystem::status().type() is " << types
[stat
.type()] << std::endl
;