如何在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");
}