Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::filesystem::perm_options

      From cppreference.com
      <cpp‎ |filesystem
       
       
      Filesystem library
      Classes
      Functions
      File types
       
      Defined in header<filesystem>
      enumclass perm_options{

          replace=/* unspecified */,
          add=/* unspecified */,
          remove=/* unspecified */,
          nofollow=/* unspecified */

      };
      (since C++17)

      This type represents available options that control the behavior of the functionstd::filesystem::permissions().

      perm_options satisfies the requirements ofBitmaskType (which means the bitwise operatorsoperator&,operator|,operator^,operator~,operator&=,operator|=, andoperator^= are defined for this type).

      [edit]Member constants

      At most one ofadd,remove,replace may be present, otherwise the behavior of the permissions function is undefined.

      Enumerator Meaning
      replace permissions will be completely replaced by the argument topermissions() (default behavior)
      add permissions will be replaced by the bitwise OR of the argument and the current permissions
      remove permissions will be replaced by the bitwise AND of the negated argument and current permissions
      nofollow permissions will be changed on the symlink itself, rather than on the file it resolves to

      [edit]Example

      Run this code
      #include <filesystem>#include <fstream>#include <iostream> void demo_perms(std::filesystem::perms p){usingstd::filesystem::perms;auto show=[=](char op, perms perm){std::cout<<(perms::none==(perm& p)?'-': op);};    show('r', perms::owner_read);    show('w', perms::owner_write);    show('x', perms::owner_exec);    show('r', perms::group_read);    show('w', perms::group_write);    show('x', perms::group_exec);    show('r', perms::others_read);    show('w', perms::others_write);    show('x', perms::others_exec);std::cout<<'\n';} int main(){std::ofstream("test.txt");// create file std::cout<<"Created file with permissions: ";    demo_perms(std::filesystem::status("test.txt").permissions()); std::filesystem::permissions("test.txt",std::filesystem::perms::owner_all|std::filesystem::perms::group_all,        std::filesystem::perm_options::add); std::cout<<"After adding u+rwx and g+rwx:  ";    demo_perms(std::filesystem::status("test.txt").permissions()); std::filesystem::remove("test.txt");}

      Possible output:

      Created file with permissions: rw-r--r--After adding u+rwx and g+wrx:  rwxrwxr--

      [edit]See also

      modifies file access permissions
      (function)[edit]
      (C++17)
      identifies file system permissions
      (enum)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/filesystem/perm_options&oldid=182040"

      [8]ページ先頭

      ©2009-2025 Movatter.jp