Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # script powershell pour lire tous les fichiers image d'un répertoire et déplacer dans un répertoire nommé CORROMPU les fichiers anormaux
- # formats gérés: heic/jpg/tga/tif/raw/png/gif/bmp/exr/webp/jp2/cr2
- # Nécessite IDENTIFY.EXE de la suite ImageMagick: https://imagemagick.org/script/download.php
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- function Select-FolderDialog {
- $folderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog
- $dialogResult = $folderBrowser.ShowDialog()
- if ($dialogResult -eq [System.Windows.Forms.DialogResult]::OK) {
- return $folderBrowser.SelectedPath
- } else {
- return $null
- }
- }
- function Scan-Images {
- param (
- [string]$directoryPath,
- [string]$identifyPath
- )
- # Start transcript journalisation
- $logFile = Join-Path -Path $directoryPath -ChildPath "scan_log.txt"
- Start-Transcript -Path $logFile
- try {
- $corruptedDir = Join-Path -Path $directoryPath -ChildPath "CORROMPU"
- $imageFiles = Get-ChildItem -Path $directoryPath -Include *.exr, *.webp, *.heic, *.jp2, *.jpg, *.cr2, *.jpeg, *.tga, *.tif, *.raw, *.png, *.gif, *.bmp -File -Recurse
- $corruptedFound = $false
- foreach ($file in $imageFiles) {
- $output = & "$identifyPath" $file.FullName 2>&1
- if ($output -match "corrupt" -or $output -match "Corrupt" -or $output -match "ERROR") {
- if (-not (Test-Path -Path $corruptedDir)) {
- New-Item -ItemType Directory -Path $corruptedDir | Out-Null
- }
- Move-Item -Path $file.FullName -Destination $corruptedDir
- $corruptedFound = $true
- Write-Output "Moved corrupted file: $($file.FullName) to $corruptedDir"
- }
- }
- if (-not $corruptedFound) {
- Write-Output "No corrupted files found."
- }
- } catch {
- Write-Error "An error occurred: $_"
- } finally {
- # fin de journalisation
- Stop-Transcript
- }
- [System.Windows.Forms.MessageBox]::Show("Tri terminé.", "Information", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Information)
- }
- # looogique
- $scriptDir = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
- # construction du chemin d'identify à partir de l'emplacement où est le script powershell
- $identifyExePath = Join-Path -Path $scriptDir -ChildPath "identify.exe"
- $selectedFolder = Select-FolderDialog
- if ($selectedFolder) {
- Scan-Images -directoryPath $selectedFolder -identifyPath $identifyExePath
- } else {
- Write-Output "No folder selected."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement