std::experimental::filesystem:: absolute, std::experimental::filesystem:: system_complete
From cppreference.net
<
cpp
|
experimental
|
fs
|
헤더 파일에 정의됨
<experimental/filesystem>
|
||
|
path absolute
(
const
path
&
p,
const
path
&
base
=
current_path
(
)
)
;
|
(1) | (filesystem TS) |
|
path system_complete
(
const
path
&
p
)
;
path system_complete ( const path & p, error_code & ec ) ; |
(2) | (filesystem TS) |
1)
다음 규칙에 따라
p
의
base
에 대한 절대 경로를 반환합니다:
-
- 만약 p 가 루트 이름과 루트 디렉터리를 모두 가지고 있는 경우(예: "C:\users" ), 경로는 수정 없이 반환됩니다.
- 만약 p 가 루트 디렉터리가 뒤따르지 않는 루트 이름을 가지고 있는 경우(예: "C:text.txt" ), base 가 p 의 루트 이름과 나머지 부분 사이에 삽입됩니다. 공식적으로 p. root_name ( ) / fs :: absolute ( base ) . root_directory ( ) / fs :: absolute ( base ) . relative_path ( ) / p. relative_path ( ) 가 반환됩니다.
- 만약 p 가 루트 이름은 없지만 루트 디렉터리를 가지고 있는 경우(예: POSIX 시스템의 "/var/tmp/file.txt" 또는 Windows의 "\users \A BC\Document.doc" ), base 의 루트 이름(있는 경우)이 p 앞에 추가됩니다(POSIX 시스템에서는 p 가 수정되지 않으며, Windows 시스템에서는 "\users \A BC\Document.doc" 가 "C:\users \A BC\Document.doc" 가 됩니다). 공식적으로 fs :: absolute ( base ) . root_name ( ) / p 가 반환됩니다.
- 만약 p 가 루트 이름과 루트 디렉터리를 모두 가지고 있지 않은 경우(예: "../file.txt" ), 전체 base 가 p 앞에 추가됩니다. 공식적으로 absolute ( base ) / p 가 반환됩니다.
2)
경로명
p
를 바탕으로 OS 파일 열기 API가 접근하게 될 파일을 식별하는 절대 경로를 획득합니다.
POSIX 시스템에서는 기본
base
(
fs::current_path()
)를 사용한
(1)
과 동일합니다. Windows 시스템에서는 각 논리 드라이브가 자신의 현재 작업 디렉토리를 가지므로,
p
가 아직 절대 경로가 아니면서 루트 이름 구성 요소를 포함하는 경우(예:
"E:filename.txt"
), 해당 드라이브의 현재 작업 디렉토리가 사용되며, 이는 이전에 실행된 프로그램에 의해 설정되었을 수 있습니다.
목차 |
매개변수
| p | - | 절대 형태로 변환할 경로 |
| base | - | 시작 위치로 사용할 경로 (반드시 절대 경로일 필요는 없음) |
| ec | - | non-throwing 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
위에서 설명한 대로 p 와 base 를 결합하여 형성된 절대(반드시 정규화된 것은 아닌) 경로를 반환합니다.
예외
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument, base as the second argument, and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has
noexcept
명세:
noexcept
참고 사항
루트 이름을 지원하는 시스템(예: Windows)에서, 상대 경로에 루트 이름이 있는 경우(예:
"D:file.txt"
)
absolute
를 호출할 때
base
의 루트 이름이 다른 경우, 일반적으로 존재하지 않는 경로가 생성됩니다.
예제
이 코드 실행
#include <filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::path p = "C:cl.exe"; std::cout << "Current path is " << fs::current_path() << '\n' << "Absolute path for " << p << " is " << fs::absolute(p) << '\n' << "System complete path for " << p << " is " << fs::system_complete(p) << '\n'; }
가능한 출력:
Current path is "D:/local/ConsoleApplication1" Absolute path for "C:cl.exe" is "C:/local/ConsoleApplication1/cl.exe" System complete path for "C:cl.exe" is "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\cl.exe"
참고 항목
|
정규 경로를 구성함
(함수) |