Skip to main content

Suppression de dossier à partir d'un export

 

$csvFilePath = "le fichier csv"
$folderNameColumn = "le nom de la colonne"
$directoryPath = "le chemin\"

# Read the CSV file
$csvData = Import-Csv -Path $csvFilePath

# Delete folders
$csvData | ForEach-Object {
    $folderName = $_.$folderNameColumn
    $folderPath = Join-Path -Path $directoryPath -ChildPath $folderName

    if (Test-Path -Path $folderPath -PathType Container) {
        try {
            Remove-Item -Path $folderPath -Recurse -Force
            Write-Host "Deleted folder: $folderName"
        }
        catch {
            Write-Host "Failed to delete folder: $folderName - $_"
        }
    }
    else {
        Write-Host "Folder not found: $folderName"
    }
}