Boost:Filesystem
Macro
-
BOOST_FILESYSTEM_DYN_LINK
: 동적링크를 위한 매크로. 이 경우boost_filesystem
라이브러리를 Link해야 한다. 또한boost_system
라이브러리도 링크해야 한다. -
BOOST_FILESYSTEM_NO_LIB
: 정적링크를 위한 매크로.
Generic vs Native
Class path deals with two different pathname formats - generic format and native format. For POSIX-like file systems, these formats are the same. But for users of Windows and other non-POSIX file systems, the distinction is important. Even programmers writing for POSIX-like systems need to understand the distinction if they want their code to be portable to non-POSIX systems.
- The generic format is the familiar
/my_directory/my_file.txt
format used by POSIX-like operating systems such as the Unix variants, Linux, and Mac OS X. Windows also recognizes the generic format, and it is the basis for the familiar Internet URL format. The directory separator character is always one or more slash characters.
- The native format is the format as defined by the particular operating system. For Windows, either the slash or the backslash can be used as the directory separator character, so
/my_directory\my_file.txt
would work fine. Of course, if you write that in a C++ string literal, it becomes"/my_directory\\my_file.txt"
.
Current Directory
- Stackoverflow: Boost::file_system how to find out in which directory your executable is?
- Stackoverflow: Get path of executable
현재 디렉토리는 아래와 같이 확인할 수 있다.
// current working directory
fs::path full_path( fs::current_path<fs::path>() );
std::cout << full_path << std::endl;
std::cout << full_path.stem() << std::endl;
Temp file
임시파일명 획득 방법은 아래와 같다.
// Boost.Filesystem VERSION 3 required
#include <string>
#include <boost/filesystem.hpp>
boost::filesystem::path temp = boost::filesystem::unique_path();
const std::string tempstr = temp.native(); // optional
Example
파일 존재여부 확인:
파일 삭제:
Favorite site
- Boost Filesystem v3 Introduction
- Boost Filesystem v3 Reference Documentation
- boost라이브러리의 filesystem사용 1강