[英]Can not delete files from Recent folder
I am writing a Software that can delete Temporary files, Prefetch data, files in Recent folder and so on. 我正在编写一个可以删除临时文件,预取数据,“最近”文件夹中的文件等的软件。 My problem is I can delete files from Temp folder successfully, but when I try for Recent folder, an exception is thrown, "Access to path...is denied".
我的问题是我可以成功地从Temp文件夹中删除文件,但是当我尝试使用“最近”文件夹时,将引发异常,“拒绝访问路径...”。 PS: According to some other questions, I have set File attributes to normal, but still no luck.
PS:根据其他一些问题,我已将File属性设置为normal,但仍然没有运气。 Please help me on this issue.
请帮我解决这个问题。 For your better understand, I put some code here:
为了让您更好地理解,我在此处添加了一些代码:
public Boolean CleanRecentData()
{
isAllClean = true;
String SysRecentPath = System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\Recent";
DirectoryInfo SysRecDir = new DirectoryInfo(SysRecentPath);
File.SetAttributes(SysRecentPath, FileAttributes.Normal);
foreach (FileInfo fi in SysRecDir.GetFiles()) //Access Denied
//Exception is thrown here
{
try
{
fi.Delete();
}
catch (Exception ex)
{
recentLogLines.AppendLine(ex.Message);
isAllClean = false;
}
}
foreach (DirectoryInfo dir in SysRecDir.GetDirectories())
{
try
{
dir.Delete(true);
}
catch (Exception ex)
{
recentLogLines.AppendLine(ex.Message);
isAllClean = false;
}
}
return isAllClean;
}
Are you able to access the Recent folder via Windows Explorer? 您可以通过Windows资源管理器访问“最近”文件夹吗?
You could go ahead and change the permissions in your system, but NOT in your users systems. 您可以继续更改系统中的权限,但不能更改用户系统中的权限。 Therefore you could handle this exception condition in two ways.
因此,您可以通过两种方式处理此异常情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.