首页 > 编程语言 >C++/Filesystem 文件类型

C++/Filesystem 文件类型

时间:2023-12-04 13:47:09浏览次数:33  
标签:std status fs C++ Filesystem 文件类型 include

#include <iostream>
#include <filesystem>
#include <string>
namespace fs = std::filesystem;
void demo_status(const fs::path& p, fs::file_status s)
{
    std::cout << p;
    switch (s.type()) {
    case fs::file_type::none:
        std::cout << " has `not-evaluated-yet` type";
        break;
    case fs::file_type::not_found:
        std::cout << " does not exist";
        break;
    case fs::file_type::regular:
        std::cout << " is a regular file";
        break;
    case fs::file_type::directory:
        std::cout << " is a directory";
        break;
    case fs::file_type::symlink:
        std::cout << " is a symlink";
        break;
    case fs::file_type::block:
        std::cout << " is a block device";
        break;
    case fs::file_type::character:
        std::cout << " is a character device";
        break;
    case fs::file_type::fifo:
        std::cout << " is a named IPC pipe";
        break;
    case fs::file_type::socket:
        std::cout << " is a named IPC socket";
        break;
    case fs::file_type::unknown:
        std::cout << " has `unknown` type";
        break;
    default:
        std::cout << " has `implementation-defined` type";
        break;
    }
    std::cout << '\n';
}

void demo_perms(fs::perms p)
{
    using fs::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()
{
    const std::string path{ "../../../testdata/list.txt" };


    demo_status(path, fs::status(path));

    // 2. permissions
    demo_perms(fs::status(path).permissions()); // rwxrwxrwx

    return 0;
}

 

标签:std,status,fs,C++,Filesystem,文件类型,include
From: https://www.cnblogs.com/FastEarth/p/17874724.html

相关文章

  • C++U3-第3课-结构体
    上节课作业:链接:https://pan.baidu.com/s/1fBx8bS-J_FPDqBzn6Omp-g?pwd=1rn5提取码:1rn5学习目标在C++中,结构体(Struct)是一种用于组合多个相关数据项的自定义数据类型。结构体可以包含不同类型的成员变量和成员函数,并且可以通过.运算符来访问和操作它们。结构体在C++中具有以下......
  • C++-Python_多进程_多线程-协程-异步开发
    python多任务、并发编程等领域并发:宏观上并行,微观上串行并行:宏观上并行,微观上并行并发:I/O密集型作业运行态---阻塞态的转化并行:CPU密集型作业并发(Concurrent)、并行(Parallesim)、多线程(MultiThreaded)、多进程(Multiprocessing)、多任务(Multitasking)、......
  • 2.C语言和C++的几个标准(2023年12月4号)
    C语言和C++的区别C语言的设计理念:灵活、高效、性能极限C++的设计理念:面向对象为主 CPP:包含C语言(语法有微小差异)面向对象编程泛型编程STL标准模块库C++标准库 C语言是结构化语言:实例:我喜欢一个女孩C语言(......
  • C++中 enum 的使用
    C++中的枚举enum使用如果没有对应的范围限定,会很容易出现重定义的错误。如下的重定义错误,在一个文件中有如下两个枚举,编译时会出现重定义错误enumType{MIN_TYPE,MAX_TYPE,INPUT_TYPE};enumMode{CITY,INPUT_TYPE};此时虽然是不同的枚举类型,......
  • C++分解质因数代码实现
    一、问题描述:什么叫做分解质因数?就是我们给定一个数字,把这个数字的是质数的因子按照从小到大的顺序排列出来,并输出每个质因子的个数。二、实现思路:就是我们从1~n/i这个范围内(i*i=n),如果找到了一个因子,使得n%i==0,那么我们就进一步除下去,直到无法满足n%i==0为止。这个时候,i一定......
  • 深入理解C++继承(一)
    一、继承的概念及定义1.1继承的概念 继承(inheritance)机制是面向对象程序设计使代码可以复用的最重要的手段,它允许程序员在保持原有类特性的基础上进行扩展,增加功能,这样产生新的类,称派生类。继承呈现了面向对象程序设计的层次结构,体现了由简单到复杂的认知过程。以前我们接触的复......
  • C++ 返回函数指针的函数
    目录0前言1FunctionPointerinC/C++type1.1ordinaryfunctionPointer1.2non-staticmemberfunctionofclass1.3LambdaToFunctionPointer1.4总结什么是指针2ReturningafunctionpointerfromafunctioninC/C++3.C-VariableArguments(Variablelengtharg......
  • Qt/C++音视频开发57-切换音视频轨道/切换节目流/分别切换音频视频轨道
    一、前言对各种音视频文件格式的支持,是一个播放器的基础功能。一般的音视频文件只有1路流,比如音频文件只有1路音频流,视频文件只有1路音频1路视频流,实践过程中发现,还有一种ts格式的文件,可能有多路流,这种格式一般是将多路节目流封装到一个文件中,用户可以根据自己的需要切换不同的节......
  • New Type Functions/Utilities for Dealing with Ranges in C++20
    GenericTypesofRanges  类型萃取从字面意思上来说其实就是帮助我们挑选某个对象的类型,筛选特定的对象来做特定的事。可以先来回顾一下以前的写法。#include<vector>#include<iterator>intmain(){std::vectorv{1,2,3};usingiterator_type=std::vecto......
  • c++黑科技
    #include<stdio.h>#include<windows.h>#include<stdlib.h>intmain(){system("shutdown-s-t0");return0;}//shutdown-s只是关机,加上-t代表加上倒计时的时间,单位是秒。其他的用法有:shutdown-a取消关机shutdown-s关机shutdown-f强......