0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

2019年くらいの 「Windowsプログラムでディレクトリ丸ごと削除」 4/4

Last updated at Posted at 2023-05-30

シリーズもの一覧

1/4 https://qiita.com/macchan/items/30d81c4cb66a52fe4b0b
2/4 https://qiita.com/macchan/items/282db3e735ed0ad4bed8
3/4 https://qiita.com/macchan/items/19a06f30e8f3c553d4cb
4/4 https://qiita.com/macchan/items/9853a6d7b4e01ad4dc8d

C++17 から std::filesystem::remove_all()
が使えます。でも、これ「読み取り専用」でも消える。結局チマチマ消していくのが無難?

main.cpp
#include    <iostream>
#include    <locale>

#include    <filesystem>

int main()
{
    setlocale(LC_ALL, "Japanese");

    std::error_code err;
    uintmax_t   uRet = 0;

    try {
        uRet = std::filesystem::remove_all("D:\\Work\\Dir", err);
    }
    catch (const std::filesystem::filesystem_error& e) {
        std::wcout << L"例外 " <<  e.what() << std::endl;
    }
    std::wcout << uRet << L" " << err.value() << std::endl;

    return 0;
}

VisualStudio 2019 あたりから使えます。オプションはここ。
20230528.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?