# Script pour créer un certain nombre de dossiers de même nom avec un n° qui change # Source : https://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell Clear-Host Invoke-Command -ScriptBlock { $source_folder = "PATH_WHERE_TO_CREATE_FOLDERS" $nb_folder = 10 # Base Name : (number will be added after with a space) $folder_to_create = "My Folder Base NAME" function Test-Directory { param ( [Parameter(Mandatory)]$path_to_verify ) If (!(test-path $path_to_verify)) { New-Item -ItemType "Directory" -Force -Path $path_to_verify Write-Host "The path $path_to_verify (or one of the last subfolder) didn't exist. It has been created." -ForegroundColor "DarkBlue" } else { Write-Host "The path $path_to_verify already exist." -ForegroundColor "DarkBlue" } } for ($i = 1 ; $i -le $nb_folder ; $i++) { $folder_name = $folder_to_create + " $i" # Exceptions if ( $folder_name -eq "My Folder Base NAME 9" ) { $folder_name = "My Folder Base NAME Part.1" } elseif ( $folder_name -eq "My Folder Base NAME 10" ) { $folder_name = "My Folder Base NAME Part.2" } # Construction of the final folder name $final_folder_name = $source_folder + "\" + $folder_name Test-Directory $final_folder_name } }