Petits scripts pas forcément méga utile, mais peut simplifier ces actions longues à faire manuellement

This commit is contained in:
MilesTEG 2021-12-28 09:36:22 +01:00
parent b812d7f769
commit f11ed91101
2 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,46 @@
# 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
}
}

View File

@ -0,0 +1,14 @@
# Script pour tester si le dossier mis en paramètre contient des dossiers vides
# et si oui, les supprimer.
# Source : https://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell
Clear-Host
Invoke-Command -ScriptBlock {
$folder_to_check = "PATH_TO_FOLDER_CONTAINING_EMPTY_FOLDERS"
$dirs = Get-ChildItem $folder_to_check -Directory -Recurse | Where-Object { (Get-ChildItem $_.fullName).count -eq 0 } | Select-Object -ExpandProperty FullName
$dirs | Foreach-Object { Write-Host "Dossier qui sera supprimer car considéré comme vide : " $_ }
# $dirs | Foreach-Object { Remove-Item $_ }
}