VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 340,137 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 3,913 people online right now. Registration is fast and FREE... Join Now!




Delete the contents of a directory

Delete the contents of a directory without deleting the directory itself.

Submitted By: RodgerB
Actions:
Rating:
Views: 3,056

Language: VB.NET

Last Modified: January 1, 1970
Instructions: 1) Copy and paste this subroutine into a class.

2) Read the information on how to call the snippet.

Snippet


  1. ''' <summary>
  2. ''' Deletes the contents of a directory.
  3. ''' </summary>
  4. ''' <param name="dir">Directory to delete the contents of.</param>
  5.  
  6. Public Sub DeleteDirContents(ByVal dir As IO.DirectoryInfo)
  7.     Dim fa() As IO.FileInfo
  8.     Dim f As IO.FileInfo
  9.  
  10.     fa = dir.GetFiles
  11.  
  12.     For Each f In fa
  13.         f.Delete()
  14.     Next
  15.  
  16.     Dim da() As IO.DirectoryInfo
  17.     Dim d1 As IO.DirectoryInfo
  18.  
  19.     da = dir.GetDirectories
  20.     For Each d1 In da
  21.         DeleteDirContents(d1)
  22.     Next
  23. End Sub
  24.  
  25. ' To use the subroutine, use this code inside a subroutine.
  26. ' "c:\lol" being the path you would like to use.
  27. DeleteDirContents(New IO.DirectoryInfo("c:\lol"))

Copy & Paste


Comments

There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month