如何使用 IFileOperation 清空文件夹 [英] How do I empty a folder using IFileOperation

查看:46
本文介绍了如何使用 IFileOperation 清空文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的辅助方法:

I have a helper method that looks like this:

HRESULT DeleteFolderAndContainedFiles(IShellItem *psiFolder)
{
    IFileOperation *pfo;
    HRESULT hr = CreateAndInitializeFileOperation(IID_PPV_ARGS(&pfo));
    if (SUCCEEDED(hr))
    {
        hr = pfo->DeleteItem(psiFolder, NULL);
        if (SUCCEEDED(hr))
        {
            hr = pfo->PerformOperations();
        }
        pfo->Release();
    }
    return hr;
}

如何使用 IShellItem(我没有使用过)调用此方法?我想向它传递一个类似 C:\data\test 的路径,它应该清除 test 目录下的所有内容,但不删除 test 目录.

How can I call this method, using IShellItem (which I have no experience with)? I want to pass it a path like C:\data\test and it should clear everything under the test directory but not delete the test directory.

推荐答案

IShellItem* item = NULL;
SHCreateItemFromParsingName(L"C:\\data\\test", NULL, IID_PPV_ARGS(&item));

这篇关于如何使用 IFileOperation 清空文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆