Code : Tout sélectionner
#include <GUIConstants.au3>
#include <File.au3>
Dim $Form1, $Oldext, $iOldext, $Newext, $iNewext, $Infolog, $infodos, $Parcourir, $iParcourir, $QUitter, $Appliquer, $Annuler
$Form1 = GUICreate("Modifext", 346, 250, 311, 218)
$Oldext = GUICtrlCreateLabel("Ancienne extension :", 24, 64, 103, 17)
$Newext = GUICtrlCreateLabel("Nouvelle extension :", 24, 96, 100, 17)
$Infolog = GUICtrlCreateLabel("Ce programme vous permet de modifier des extensions par lot.", 24, 16, 295, 17)
$iOldext = GUICtrlCreateInput("", 128, 56, 105, 25)
$iNewext = GUICtrlCreateInput("", 128, 88, 105, 25)
$infodos = GUICtrlCreateLabel("Dossier dans lequel se trouve les fichiers à modifier :", 24, 152, 253, 17)
$iParcourir = GUICtrlCreateInput("", 24, 176, 193, 27)
$Parcourir = GUICtrlCreateButton("(Not allowed)", 224, 176, 96, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\Mick\Bureau\Koda\Parcourir.bmp", 0)
$Quitter = GUICtrlCreateButton("(Not allowed)", 192, 216, 96, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\Mick\Bureau\Koda\Quitter.bmp", 0)
$Appliquer = GUICtrlCreateButton("(Not allowed)", 56, 216, 94, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\Mick\Bureau\Koda\Appliquer.bmp", 0)
$Tab1 = GUICtrlCreateTab(8, 8, 329, 201)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Quitter
Exit
Case $Parcourir
$dir = FileSelectFolder ( "Selectionnez le dossier", "" , 7 , @ScriptDir )
GUICtrlSetData($iParcourir,$dir)
Case $Appliquer
Appliquer(GUICtrlRead($iParcourir),GUICtrlRead($iNewext),GUICtrlRead($iOldext))
EndSwitch
WEnd
Func Appliquer($Rep,$New_ext,$Old_ext)
FileChangeDir($Rep)
$Search = FileFindFirstFile("*." & $Old_ext)
If $Old_ext = "" or $New_ext= "" or $Rep = "" Then
MsgBox(0, "Erreur", "Merci de remplir tous les champs.")
Else
If $Search = -1 Then
MsgBox(0, "Erreur", "Aucun fichier n'a été trouvé.")
Else
While 1
$File = FileFindNextFile($search)
If @error Then ExitLoop
$File2 = StringReplace($File,$Old_ext, $New_ext)
$Ok = FileMove($File,$File2)
; If $Ok = 1 then _FileWriteLog(".\renommage.log", ":: OK : " & $File)
; If $Ok = 0 then _FileWriteLog(".\renommage.log", ":: ECHEC : " &$File)
WEnd
FileClose($Search)
MsgBox(0, "Opération terminé", "L’opération a été effectuée avec succès.")
EndIf
EndIf
EndFunc