c#如何获取回收站文件信息

wuliao000000 2010-12-08 07:14:43
如题,自己看有些说在“c:\\Recycled”下查找文件,但这个貌似行不通,就算获取了回收站路径,里面文件能像普通文件处理么?
...全文
419 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hengren4 2013-08-16
  • 打赏
  • 举报
回复
我来定个位子
龍过鸡年 2010-12-08
  • 打赏
  • 举报
回复
这个有意思!
我觉得 WinAPI 烦,搞了个文件夹搜索的方法,你试试

原理是搜索各个驱动器下包含 recycle 字符的文件夹
判断文件夹属性是否包含隐藏和系统


Type type = typeof(System.IO.FileAttributes);

Console.WriteLine("values\tattributes");
Console.WriteLine("-----------------------------");

foreach (int value in Enum.GetValues(type))
{
Console.WriteLine("{0}\t{1}",
value, Enum.GetName(type, value));
}

Console.WriteLine("-----------------------------");

foreach (var drive in System.IO.DriveInfo.GetDrives())
{
if (drive.DriveType == System.IO.DriveType.Fixed)
{
System.IO.DirectoryInfo[] folders =
drive.RootDirectory.GetDirectories("*recycle*");

foreach (var folder in folders)
{
Console.Write("({0})\t",
(folder.Attributes & System.IO.FileAttributes.Directory)
== System.IO.FileAttributes.Directory &&
(folder.Attributes & System.IO.FileAttributes.Hidden)
== System.IO.FileAttributes.Hidden &&
(folder.Attributes & System.IO.FileAttributes.System)
== System.IO.FileAttributes.System);

Console.WriteLine(folder.FullName);
Console.WriteLine("\tsttribs: {0}", folder.Attributes);
}
}
}
wuliao000000 2010-12-08
  • 打赏
  • 举报
回复
判断C盘根目录下面的"Recycled"目录是否为空。
这个之前看过,但自己的Recycled文件夹是隐藏的,而且是空的,
自己回收站貌似在C:\RECYCLER\S-1-5-21-1659004503-1788223648-1177238915-1003
但用FileInfo不能正常获取下面的文件啊


自己看用static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,[Out] StringBuilder lpszPath, int nFolder, bool fCreate)获取特殊文件路径
看上面写的const int CSIDL_BITBUCKET =0x000a; // <desktop>\Recycle Bin
那自己觉得10该是回收站对应的值,可用了之后,返回路径是空的,自己试了其他值貌似都正常啊
wuliao000000 2010-12-08
  • 打赏
  • 举报
回复
不好意思,string[] MyFiles=Directory.GetFiles(driver+"\\Recycled"); driver是啥啊?
wq326431904 2010-12-08
  • 打赏
  • 举报
回复
看看哦 学习
wolftop 2010-12-08
  • 打赏
  • 举报
回复
string[] MyFiles=Directory.GetFiles(driver+"\\Recycled");

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧