I want to get the current directory of the topmost Terminal tab/window (via AppleScript or something else, it doesn't really matter). How can I do that?


Question: My.Computer.FileSystem.DeleteDirectory() with read only files?
Answer: The short answer is there isn't a method provided in the framework. You have to develop your own. What you have written is good. I prefer the following as it make use of extension methods and more clearly describes what the method does.

Imports System
Imports System.IO
Imports System.Runtime.CompilerServices
Imports System.Linq

Public Module DirectoryExtensions

    &lt;Extension()&gt;
    Public Sub Delete(directory As DirectoryInfo, 
                      recursive As Boolean, 
                      forceReadOnlyDelete As Boolean
    )
        directory.ForceDelete()
    End Sub

    &lt;Extension()&gt;
    Public Sub ForceDelete(ByVal directory As DirectoryInfo)

        directory.RemoveReadOnlyAttributeFromFiles(True)
        directory.Delete(True)

    End Sub

    &lt;Extension()&gt;
    Public Sub RemoveReadOnlyAttributeFromFiles(ByVal directory As DirectoryInfo, ByVal recursive As Boolean)

        Dim readOnlyFiles = From f In directory.GetFiles()
            Where (f.Attributes And FileAttributes.ReadOnly) = FileAttributes.ReadOnly

        For Each file In readOnlyFiles
            file.Attributes = FileAttributes.Normal
        Next

        If recursive Then

            For Each subDirectory In directory.GetDirectories()
                subDirectory.RemoveReadOnlyAttributeFromFiles(True)
            Next

        End If

    End Sub

End Module