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?

More than 1 year has passed since last update.

2019年くらいの 「Windowsプログラムでディレクトリ丸ごと削除」 2/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

 DemoveDirectory を調べていくと、以下のような記載を見つけました。

ディレクトリ内のファイルを再帰的に削除するには、 SHFileOperation 関数を使用します。

https://learn.microsoft.com/ja-jp/windows/win32/api/fileapi/nf-fileapi-removedirectorya
https://learn.microsoft.com/ja-jp/windows/win32/api/fileapi/nf-fileapi-removedirectoryw

はい。書きました。面倒になっています。
「読み取り専用」属性のファイルもディレクトリも消える凶悪さです。

main.cpp
#include	<iostream>
#include	<Windows.h>

int main()
{
	SHFILEOPSTRUCT	op;
	op.hwnd = NULL;
	op.wFunc = FO_DELETE;
	op.pFrom = L"D:\\Work\\Dir";
	op.pTo = NULL;
	op.fFlags = FOF_NO_UI;
	// op.fAnyOperationsAborted このメンバは出力に使用される
	op.hNameMappings = NULL;
	op.lpszProgressTitle = NULL;

	int nResult = SHFileOperation(&op);
	std::cout << nResult << std::endl;

	return 0;
}

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?