Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Folder Delete Everything

Posted on December 14, 2013October 26, 2015 By David Kittell

Careful with this function as it can really do some serious damage if you choose the wrong folder.

 'Folder Delete Everything - Start
    Private Sub DeleteDirectory(ByVal dir_name As String)
        Try
            Dim file_name As String
            Dim files As Collection
            Dim i As Integer

            ' Get a list of files it contains.
            files = New Collection
            file_name = Dir$(dir_name & "*.*", vbReadOnly + _
                vbHidden + vbSystem + vbDirectory)
            Do While Len(file_name) > 0
                If (file_name <> "..") And (file_name <> ".") Then
                    files.Add(dir_name & "" & file_name)
                End If
                file_name = Dir$()
            Loop

            ' Delete the files.
            For i = 1 To files.Count
                file_name = files(i)
                ' See if it is a directory.
                If GetAttr(file_name) And vbDirectory Then
                    ' It is a directory. Delete it.
                    DeleteDirectory(file_name)
                Else
                    ' It's a file. Delete it.
                    'lblStatus.Text = file_name
                    'lblStatus.Refresh()
                    SetAttr(file_name, vbNormal)
                    Kill(file_name)
                End If
            Next i

            ' The directory is now empty. Delete it.
            'lblStatus.Text = dir_name
            'lblStatus.Refresh()
            RmDir(dir_name)
        Catch ex As Exception
            'handle any errors that occurred
        End Try
    End Sub
    'Folder Delete Everything - Stop
Try
   DeleteDirectory("c:windows")
Catch ex As Exception
End Try
Originally Posted on December 14, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code VB.NET

Post navigation

Previous post
Next post

Related Posts

UNIX – List USB Devices With lsusb

Posted on February 12, 2018February 12, 2018

On the Mac “lsusb -v” is rather clean in comparison to other systems. # If not already installed… # brew update && brew tap jlhonora/lsusb && brew install lsusb lsusb -v lsusb -v # or lsusb -v | grep -E ‘\<(Bus|iProduct|bDeviceClass|bDeviceProtocol|idVendor|idProduct|iManufacturer)’ 2>/dev/null All information on this site is shared with…

Read More

PowerShell – Get-TinyURL API Call

Posted on December 14, 2015February 12, 2016

clear Function Get-TinyURL { #PowerShell – Get-TinyURL API Call param ( [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [String] $sHTTPLink ) if ($sHTTPLink.StartsWith("http://") -eq $true -or $sHTTPLink.StartsWith("https://") -eq $true) { if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient } $webClient.DownloadString("http://tinyurl.com/api-create.php?url=" + [System.Web.HttpUtility]::UrlEncode($sHTTPLink)) } else { Write-Output "Bad Link, please include http:// or https://" } } Get-TinyURL "http://google.com" GitHub:…

Read More

File Name Converter

Posted on July 18, 2013October 26, 2015

<% @LANGUAGE = VBSCRIPT %> <%Option Explicit%> <% ‘ File Name Move and Converter ‘ Written by Cristiano Guglielmetti: guglielmetti@tin.it ‘ Dec.2001 ‘ This script moves and renames files into a webserver from a dir to another dir ‘ especially designed for large numbers of pictures files Response.Write "<html>" &…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes