Namespaces
Variants

std::experimental::filesystem:: space

From cppreference.net
ヘッダーで定義 <experimental/filesystem>
space_info space ( const path & p ) ;
space_info space ( const path & p, error_code & ec ) noexcept ;
(filesystem TS)

p で指定されたパス名が存在するファイルシステムに関する情報を、POSIX statvfs によって取得されるように決定します。

POSIXの struct statvfs のメンバーから以下のように設定された、 space_info 型のオブジェクトを生成して返します:

  • space_info. capacity f_blocks * f_frsize によって設定されたかのように設定されます。
  • space_info. free f_bfree * f_frsize に設定されます。
  • space_info. available f_bavail * f_frsize に設定されます。
  • 特定できないメンバーはすべて static_cast < std:: uintmax_t > ( - 1 ) に設定されます。

例外を投げないオーバーロードは、エラー時にすべてのメンバーを static_cast < std:: uintmax_t > ( - 1 ) に設定します。

目次

パラメータ

p - 検査対象のパス
ec - 例外を投げないオーバーロードにおけるエラー報告用出力パラメータ

戻り値

ファイルシステム情報( space_info オブジェクト)。

例外

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 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

注記

space_info. available space_info. free より少ない場合があります。

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
    fs::space_info devi = fs::space("/dev/null");
    fs::space_info tmpi = fs::space("/tmp");
    std::cout << "         Capacity         Free    Available\n"
              << "/dev:   " << devi.capacity << "   "
              << devi.free << "   " << devi.available << '\n'
              << "/tmp: " << tmpi.capacity << ' '
              << tmpi.free << ' ' << tmpi.available << '\n';
}

出力例:

          Capacity         Free    Available
/dev:   4175114240   4175110144   4175110144
/tmp: 420651237376 411962273792 390570749952

関連項目

ファイルシステムの空き領域と利用可能な領域に関する情報
(クラス)