how to check if a directory contains any files or not?if files exist how to delete them in vb?
ramabala 0 Newbie Poster
Recommended Answers
Jump to PostPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim strDir As String = "C:\testdir\" If (System.IO.Directory.Exists(strDir)) Then Dim dir As New System.IO.DirectoryInfo("C:\testdir") Dim files As System.IO.FileInfo() = dir.GetFiles() For Each file As System.IO.FileInfo In files System.IO.File.Delete(file.FullName) Next End If End Sub
Jump to Postif
System.IO.File.Exists("fileName")
thenSystem.IO.File.Delete("fileName")
then save the new file just like you did before when it didn't exist.
Jump to PostYou're welcome
Please mark this thread as solved if you have found the answer to your original question and good luck!
All 11 Replies
GeekByChoiCe 152 Practically a Master Poster Featured Poster
ramabala 0 Newbie Poster
GeekByChoiCe 152 Practically a Master Poster Featured Poster
ramabala 0 Newbie Poster
ramabala 0 Newbie Poster
GeekByChoiCe 152 Practically a Master Poster Featured Poster
sknake 1,622 Senior Poster Featured Poster
ramabala 0 Newbie Poster
sknake 1,622 Senior Poster Featured Poster
ramabala 0 Newbie Poster
sknake 1,622 Senior Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.