简体   繁体   English

删除路径“C:\\Users\\Default\\AppData\\Roaming”中的文件夹

[英]Delete a folder which is present in the path "C:\Users\Default\AppData\Roaming"

I tried to delete a folder which is present in the path "C:\\Users\\Default\\AppData\\Roaming".我试图删除路径“C:\\Users\\Default\\AppData\\Roaming”中存在的文件夹。 Usually I use the below code to delete the folder.通常我使用下面的代码来删除文件夹。

For deleting the folder present in the desktop,要删除桌面上的文件夹,

if (Directory.Exists("folderpath"))
{
  Directory.Delete("folderpath");
}

this line will delete the folder even if it is read only.即使该文件夹是只读的,该行也会删除该文件夹。 If I copy the same folder and place it in this "C:\\Users\\Default\\AppData\\Roaming" location & run my code again I am getting the error如果我复制相同的文件夹并将其放置在此“C:\\Users\\Default\\AppData\\Roaming”位置并再次运行我的代码,我会收到错误消息

System.IO.IOException: 'Access to the path 'C:\Users\Default\AppData\Roaming\SampleFolder' is denied.'

I tried many other methods to delete the folder, but still facing the same issue.我尝试了许多其他方法来删除文件夹,但仍然面临同样的问题。 Kindly help.请帮忙。

I believe your problem relates to permissions.我相信您的问题与权限有关。 Try running the exe as administrator and see if you have access to the file.尝试以管理员身份运行 exe 并查看您是否有权访问该文件。

This is a simple file permissions issue.这是一个简单的文件权限问题。 The Default user profile is a system folder and you don't have write access to it unless you are running elevated.默认用户配置文件是一个系统文件夹,除非您运行提升,否则您对它没有写访问权限。

You can check the permissions simply by looking at the Security tab on the properties of the folder.您只需查看文件夹属性上的“安全”选项卡即可检查权限。 The Administrators local group has full access, but the Users group only has read access. Administrators 本地组具有完全访问权限,但 Users 组只有读取访问权限。 Assuming that you have UAC enabled - as you should - then you have to be running in elevated mode to be granted the rights of the Administrators group.假设您启用了 UAC - 正如您应该的那样 - 那么您必须在提升模式下运行才能被授予管理员组的权限。

In other words, you need to run your code as administrator to make changes anywhere in the default user profile.换句话说,您需要以管理员身份运行代码才能在默认用户配置文件中的任何位置进行更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 如何获取用户 AppData 文件夹,而不是 AppData\Roaming? - C# How to get the User AppData folder, NOT AppData\Roaming? 从不同PC的C:\\ Users \\ user \\ AppData \\ Roaming \\ ect运行.exe文件 - Run an .exe file from C:\Users\user\AppData\Roaming\ect from different PC's 当用户被拒绝访问AppData(漫游)文件夹时,SQL Server Compact 4.0无法在Windows 7上运行,但仍可以在Windows 10上运行 - When Users Are Denied Access To AppData (Roaming) Folder, SQL Server Compact 4.0 Cannot Work On Windows 7 But Can Still Work In Windows 10 在C#windows服务中获取appdata \\ local文件夹路径 - Get appdata\local folder path in C# windows service 如何在“AppData\\Roaming”中为 C# 中的任何用户创建文件文本 - How to create file text in "AppData\Roaming" for any user in C# 如何将user.config保存到AppData \\ Roaming文件夹而不是AppData \\ Local? - How to save user.config to AppData\Roaming folder instead of AppData\Local? 无法创建文件“c:\\ User \\ ... \\ Appdata \\ Roaming ...”。 访问被拒绝 - Cannot create file “c:\User\…\Appdata\Roaming…”. Access is denied C# 获取 %AppData% 的路径 - C# getting the path of %AppData% 尽管配置,为什么 NuGet 使用 %APPDATA%\Roaming\packages 作为存储库文件夹? - Why does NuGet uses %APPDATA%\Roaming\packages as repository folder despite configuration? 在C#中的Windows漫游文件夹中写入值 - Strore values in windows Roaming folder in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM