Functions/Remove-LocalNotebooks.ps1

Function Remove-LocalNotebooks {
    [cmdletbinding()]
    param(
        [parameter(Mandatory = $true)][string]$localPath,
        $config
    )
    $results = @{
        RemovedFolders   = 0
        RemovedNotebooks = 0
    }

    $folderContent = Get-ChildItem $localPath -Directory -Recurse 
    foreach ($object in $folderContent) {
        $WorkspaceFolder = $object.FullName.Replace($localPath, '')
        Write-Host $WorkspaceFolder "wf"
        $WorkspaceFolder = Join-Path $config.dataBricksPath $WorkspaceFolder
        $workspaceFolder = $WorkspaceFolder.Replace('\', '/')
        Write-Host $WorkspaceFolder
        Try {
            Get-DatabricksWorkspaceFolder -Path $WorkspaceFolder
        }
        Catch {           
            Write-Verbose "Folder $WorkspaceFolder not found in workspace. Deleting locally."
            Remove-Item $object.FullName -Force -Recurse
            $results.RemovedFolders = $results.RemovedFolders + 1
        }
    }

    $folderContent = Get-ChildItem $localPath -File -Recurse -Include *.py
    foreach ($object in $folderContent) {
        $notebook = $object.FullName.Replace($localPath, '')
        $notebook = Join-Path $config.dataBricksPath $notebook
        $notebook = $notebook.Replace('\', '/')
        $notebook = $notebook.Replace('.py', '')
        Write-Host $notebook
        Try {
            Get-DatabricksWorkspaceFolder -Path $notebook
        }
        Catch {
           
            Write-Verbose "File $notebook not found! Removing from local directory."
            Remove-Item $object.FullName -Force   
            $results.RemovedNotebooks = $results.RemovedNotebooks + 1
        }
    }
    return $results
}