使用C#删除文件夹 [英] Delete folder using C#

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

问题描述

我正在尝试删除位于
的文件夹


C:\Program Files \Default公司名称



我实现此代码的应用程序位于同一个文件夹中。



为此我使用了以下代码



I am trying to delete folder that is located at

C:\Program Files\Default Company Name.

The application in which i am implementing this code resides in the same folder.

For that i have used the below code

Public Sub deletefunc()
        Dim Path As String = "C:\Program Files\Default Company Name"
        Directory.Delete(Path, True)
End Sub





没有收到任何错误。

删除文件夹(我应该说隐藏)文件夹,直到下次运行。当我尝试通过快捷方式运行应用程序时,它再次显示该文件夹(我们试图删除),即它之前没有被删除。



我的问题是:如何删除特定文件夹?是否需要更新任何内容他的代码?或者如何实现其他方式?



非常感谢任何帮助。



Not getting any error.
It deletes the folder(i should say hide) folder until next run.When i try to run application through shortcut then it again shows that folder(which we attempted to delete),that is it was not deleted previously.

My question is : How to delete specific folder?Is there anything needs to be updated with this code?or how to implement other way?

Any help is really appreciated.

推荐答案

正在删除这个目录中的东西不是真正合法的操作。难怪从Window 7开始访问这个目录一直受到限制(我不算Vista)。此目录的内容已在Windows Installer数据库中注册,因此任何直接删除都可能会破坏其完整性。此类操作只能通过Windows Installer SDK完成。



对于构建安装,通常使用Visual Studio安装项目,因为它们自2012年以来已被弃用,一个很好的理由。项目类型不符合MSBuild,还有其他问题。我强烈推荐开源Microsoft Windows Installer XML工具集(WiX):

http://en.wikipedia .org / wiki / WiX [ ^ ],

http://wixtoolset.org/ [ ^ ]。



-SA
Deleting things from this directory is not really legal operation. No wonder access to this directory has been limited since Window 7 (I don''t count Vista). The content of this directory is registered with the Windows Installer database, so any direct deletion may break its integrity. Such operations can be done only via Windows Installer SDK.

For building installation, Visual Studio Setup projects are usually used, by they have been deprecated since v.2012, for a good reason. The project type is not MSBuild-compliant and has other problems. I strongly recommend open-source Microsoft Windows Installer XML Toolset (WiX):
http://en.wikipedia.org/wiki/WiX[^],
http://wixtoolset.org/[^].

—SA

http://msdn.microsoft.com/en-us/library/cc148994.aspx [ ^ ]

http:// msdn。 microsoft.com/en-us/library/system.io.directory.delete(v=vs.71).aspx [ ^ ]

删除C#中的目录 [ ^ ]
http://msdn.microsoft.com/en-us/library/cc148994.aspx[^]
http://msdn.microsoft.com/en-us/library/system.io.directory.delete(v=vs.71).aspx[^]
Delete a directory in C#[^]


这可能与您部署应用程序的方式有关吗?



我的ClickOnce应用程序将在启动之前更新...这将在应用程序启动之前重新创建文件夹结构。
Could this have anything to do with the way you''re deploying the application?

My ClickOnce applications will update before launching... This will recreate the folder structure before the app starts.


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

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