VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



RmDir

by Robert A. Charest Jr. (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

This Procedure Deletes all Files in Directory as well as all Sub Directories and Files

Inputs
vFile = Directory to Delete
API Declarations

Rate RmDir

'###########################################
'# Removes an Entire Directory Structure #
'# ------------------------------------- #
'# Created By : Robert A. Charest Jr.   #
'# E-mail   : [email protected] #
'###########################################
Public Sub RmTree(ByVal vDir As Variant)
  
  Dim vFile As Variant
  
  ' Check if "\" was placed at end
  ' If So, Remove it
  If Right(vDir, 1) = "\" Then
    vDir = Left(vDir, Len(vDir) - 1)
  End If
  
  ' Check if Directory is Valid
  ' If Not, Exit Sub
  vFile = Dir(vDir, vbDirectory)
  If vFile = "" Then
    Exit Sub
  End If
  
  ' Search For First File
  vFile = Dir(vDir & "\", vbDirectory)
  
  ' Loop Until All Files and Directories
  ' Have been Deleted
  Do Until vFile = ""
    
    If vFile = "." Or vFile = ".." Then
      vFile = Dir
    
    ElseIf (GetAttr(vDir & "\" & vFile) And _
      vbDirectory) = vbDirectory Then
      RmTree vDir & "\" & vFile
      vFile = Dir(vDir & "\", vbDirectory)
    
    Else
      Kill vDir & "\" & vFile
      vFile = Dir
    
    End If
    
  Loop
  
  ' Remove Top Most Directory
  RmDir vDir
  
End Sub

Download this snippet    Add to My Saved Code

RmDir Comments

No comments have been posted about RmDir. Why not be the first to post a comment about RmDir.

Post your comment

Subject:
Message:
0/1000 characters