MyException - 我的异常网
当前位置:我的异常网» 编程 » 罗列回收站中的文件和目录

罗列回收站中的文件和目录

www.myexceptions.net  网友分享于:2013-04-10  浏览:4次
列举回收站中的文件和目录

这个例子是在学习Shell程序设计的时候看到的,觉得不错,就记录下来。

#include <windows.h>
#include <ShlObj.h>
#include <stdio.h>

#pragma comment(lib, "Shell32.lib")

DWORD ListFileInRecycleBin();

int main()
{
	ListFileInRecycleBin();

	system("pause");
	return 0;
}

DWORD ListFileInRecycleBin()
{
	CHAR szPath[MAX_PATH];
	IShellFolder *pisf = NULL;
	IShellFolder *pisfRecBin = NULL;

	SHGetDesktopFolder(&pisfRecBin);
	IEnumIDList *peidl = NULL;
	
	LPITEMIDLIST pidlBin = NULL;
	LPITEMIDLIST pidlCurrent = NULL;

	SHGetFolderLocation(NULL, CSIDL_BITBUCKET, NULL, 0, &pidlBin);

	pisfRecBin->BindToObject(pidlBin, NULL, IID_IShellFolder, (void**)&pisf);

	pisf->EnumObjects(NULL,
		              SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN,
					  &peidl);

	STRRET strret;
	ULONG uFetched;
	HANDLE hOutPut = GetStdHandle(STD_OUTPUT_HANDLE);
	printf("\nFiles In Recycle Bin:\n");
	while (1)
	{
		if (S_FALSE == peidl->Next(1, &pidlCurrent, &uFetched))
			break;

		SHGetPathFromIDList(pidlCurrent, szPath);
		pisf->GetDisplayNameOf(pidlCurrent, SHGDN_NORMAL, &strret);

		WriteConsoleW(hOutPut, L"\t", 1, NULL, NULL);
		WriteConsoleW(hOutPut, strret.pOleStr, lstrlenW(strret.pOleStr), NULL, NULL);
		WriteConsoleW(hOutPut, L"\n", 1, NULL, NULL);
	}

	ILFree(pidlBin);
	ILFree(pidlCurrent);
	pisf->Release();
	pisfRecBin->Release();
	peidl->Release();
	
	return 0;
}

我电脑中回收站截图如下:



程序运行结果如下:




文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有