1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| @echo off & Title %~nx0 & CHCP 65001>nul
:: ############################################
:: Script hybride Batch + PowerShell
:: Supprime les secondes extensions de fichiers
:: ############################################
setlocal enabledelayedexpansion
:: Configuration
set "directoryPath=C:\chemin\vers\vos\fichiers" :: <-- À modifier
echo.
echo [1/3] Vérification de l'environnement...
powershell -command "& {Get-Command -Name Get-ChildItem -ErrorAction Stop}" >nul 2>&1
if %errorlevel% neq 0 (
echo Erreur: PowerShell n'est pas installé
pause
exit /b 1
)
:: Menu interactif
echo.
echo [2/3] Mode de fonctionnement:
echo 1. Mode simulation (affiche les changements sans modifier)
echo 2. Mode réel (effectue les renommages)
echo 3. Annuler
set /p choice="Choisissez (1-3): "
if "%choice%"=="3" exit /b
if not "%choice%"=="1" if not "%choice%"=="2" (
echo Choix invalide
pause
exit /b
)
:: Exécution du code PowerShell
echo.
echo [3/3] Traitement en cours...
echo.
set "psCommand=Get-ChildItem -Path '%directoryPath%' -Recurse -File | Where-Object { $_.Name -match '\.(\w+)\.\w{8,12}$' } | ForEach-Object {"
set "psCommand=!psCommand! $newName = $_.Name -replace '\.\w{8,12}$','';"
if "%choice%"=="1" (
set "psCommand=!psCommand! Write-Host ('[SIMULATION] ' + $_.Name + ' -> ' + $newName);"
) else (
set "psCommand=!psCommand! Rename-Item -Path $_.FullName -NewName $newName -Force;"
)
set "psCommand=!psCommand! }"
powershell -NoProfile -ExecutionPolicy Bypass -Command "& {!psCommand!}"
:: Résumé
echo.
echo Opération terminée.
if "%choice%"=="1" echo MODE SIMULATION: Aucun fichier modifié
pause
exit /b |
Partager