' version 3 du 03/02/15 a 14h17 ' Dim oFSO, repertoire, fichiers, folderIndex ' Dim nomFich1, nom_sans_ext, source, nomFich2, nomFich3 Set oFSO = CreateObject("Scripting.FileSystemObject") Set repertoire = oFSO.GetFolder(".\") ' -------- fonction moveCopyOrDelFile -------- ' retourne une chaine de caracteres correspondant aux actions demandees ' a_faire : booleen indiquant s'il faut vraiment faire les actions, ou seulement generer la chaine de caracteres en retour de fonction ' type_action, ext1, ext2, ext3 : voir parametrage ci-dessous Function moveCopyOrDelFile( type_action, a_faire, messageCR, nombreImpacts, ext1, ext2, ext3 ) messageCR = "Actions :" & vbCrLf nombreImpacts = 0 Set fichiers = repertoire.Files For each folderIndex In fichiers nomFich1 = folderIndex.Name if (right(nomFich1,Len(ext1)) = ext1) then nom_sans_ext = left(nomFich1, Len(nomFich1)-Len(ext1)) nomFich2 = nom_sans_ext & ext2 nomFich3 = nom_sans_ext & ext3 Select Case type_action Case "move" messageCR = messageCR & "MOVE " & nomFich1 & " --> " & nomFich3 & vbCrLf nombreImpacts = nombreImpacts + 1 if a_faire = True then oFSO.MoveFile nomFich1, nomFich3 end if Case "copy" messageCR = messageCR & "COPY " & nomFich1 & " --> " & nomFich3 & vbCrLf nombreImpacts = nombreImpacts + 1 if a_faire = True then oFSO.CopyFile nomFich1, nomFich3 Case "selDel" if NOT oFSO.FileExists( nomFich2 ) then messageCR = messageCR & "DEL " & nomFich1 & vbCrLf nombreImpacts = nombreImpacts + 1 if a_faire = True then oFSO.DeleteFile nomFich1 end if Case "selMove" if NOT oFSO.FileExists( nomFich2 ) then messageCR = messageCR & "MOVE " & nomFich1 & " --> " & nomFich3 & vbCrLf nombreImpacts = nombreImpacts + 1 if a_faire = True then oFSO.MoveFile nomFich1, nomFich3 end if Case Else messageCR = messageCR & "ERREUR : type_action inconnu lors de l'appel a moveCopyOrDelFile" & vbCrLf End Select End if Next End Function ' -------- parametrage des actions -------- ' actions possibles : move / copy / selDel / selMove ' pour les move ou copy toto.ext1 donnera lieu a toto.ext3 ' une action selective (delete ou move) se fera sur toto.ext1 si et seulement si le fichier toto.ext2 n'existe pas mon_action = "selDel" ' --- extensions : ' source ext1 = ".DNG" ' condition pour les actions selectives ext2 = ".JPG" ' destination ext3 = ".poub" ' -------- Programme PRINCIPAL -------- Dim messageCR, nombreImpacts ' on appelle la fonction histoire de generer le pop-up mais sans faire le boulot moveCopyOrDelFile mon_action, false, messageCR, nombreImpacts,ext1, ext2, ext3 ' Affichage du pop-up pour indiquer les impacts et demander confirmation ' le dernier parametre de MsgBox (1) produit une boite "OK / Cancel" yes_or_cancel = MsgBox( "Nombre de fichiers impactes : " & nombreImpacts & vbCrLf & vbCrLf & messageCR, 1 ) ' si des fichiers ont ete trouves, et si l'utilisateur a confirme juste ci-dessus, ' alors on applique l'action et affiche un pop-up de compte-rendu (avec seulement un bouton OK) if nombreImpacts > 0 then if yes_or_cancel = vbOK then moveCopyOrDelFile mon_action, true, messageCR, nombreImpacts, ext1, ext2, ext3 MsgBox nombreImpacts & " fichiers ont ete impactes", 0 end if end if WScript.Quit