如何在vb中删除主文件夹中的文件和文件夹? [英] How to delete files and folder form main folder in vb ?

查看:458
本文介绍了如何在vb中删除主文件夹中的文件和文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何从vb中的主文件夹中删除文件和文件夹。

i有一个主文件夹,我有一些文件和内部文件夹也有一些文件,所以我需要在vb中删除。



yybxo3fhzgcojvjj5mqv0mag\sample.txt

yybxo3fhzgcojvjj5mqv0mag\ temp\Cache \ form mail

yybxo3fhzgcojvjj5mqv0mag \ temp\Cache \ form mail \ 2014-14-01T06_22_20\100@678x.Pdf



以上yybxo3fhzgcojvjj5mqv0mag是包含的主文件夹sample.txt文件以及temp,Cache,form mail,2014-07-01T06_22_20包含子文件夹,在2014-07-01T06_22_20文件夹中包含100@678x.Pdf文件。



所以如果使用像





Hi
How to delete file and folder from main folder in vb.
i have a main folder in that i have some files and inside folder also have some file,so i need to delete in vb.

yybxo3fhzgcojvjj5mqv0mag\sample.txt
yybxo3fhzgcojvjj5mqv0mag\temp\Cache\form mail
yybxo3fhzgcojvjj5mqv0mag\temp\Cache\form mail\2014-07-01T06_22_20\100@678x.Pdf

in above "yybxo3fhzgcojvjj5mqv0mag" is main folder that contain sample.txt file and also temp,Cache,form mail,2014-07-01T06_22_20 contain subfolders,in "2014-07-01T06_22_20" folder contain 100@678x.Pdf file.

so if use like


Try
       Dim dinfo As New DirectoryInfo(Server.MapPath("") & "\yybxo3fhzgcojvjj5mqv0mag")
       If dinfo IsNot Nothing Then
           For Each finfo As FileInfo In dinfo.GetFiles()
               finfo.Delete()
           Next
           dinfo.Delete()
       End If
   Catch ex As Exception

   End Try





它会删除主文件夹中的文件但不删除文件表单子文件夹以及子文件夹需要删除。



所以如果主文件夹有文件和文件夹,如果我删除主文件夹只需要删除主文件夹,文件和子文件夹也。



请尽快回复



问候



Aravind



it will delete files form main folder only it not delete file form subfolders and also subfolders need to delete.

So if main folder have files and folder ,if i delete main folder only it need to delete main folder,files and subfolders also.

Pls reply asap

Regards

Aravind

推荐答案

VB:

VB:
Private Sub DeletFilesAndFolder()
	Dim path As String = "C:\Documents and Settings\prasad\Desktop\folder"

	If Directory.Exists(path) Then

		Directory.Delete(path, True)
	Else
		Console.WriteLine(path & " not exists")
	End If



End Sub





C#:



C#:

private void DeletFilesAndFolder()
       {
           string path = @"C:\Documents and Settings\prasad\Desktop\folder";

           if (Directory.Exists(path))

               Directory.Delete(path, true);
           else
               Console.WriteLine(path + " not exists");



       }


这篇关于如何在vb中删除主文件夹中的文件和文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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