Bonjour à tous,

Je chercher à renommer environ 300 fichiers dans un dossier avec un numéro à incrémenter, et ce peu importe le nom d’origine de chaque fichier, tout doit être remplacé. Un petit exemple :

Fichiers actuels :
Truc.JPG
Bidule.JPG
Machin.JPG


Fichiers après renommage :
Bonjour_1.JPG
Bonjour_2.JPG
Bonjour_3.JPG

Et ainsi de suite…

J’ai déjà un super script (trouvé ici, merci encore, je l’utilise régulièrement !), mais qui utilise la fonction Replace. Sauf que comme je ne cherche pas à renommer juste une chaîne de caractères dans les noms de fichiers, mais bien le nom complet, je ne trouve pas comment l’adapter. En plus du fait que j'ai aussi besoin de l'incrémentation

Le script en question :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
60
61
62
Option Explicit
If AppPrevInstance() Then 
    MsgBox "Attention ! Il ya déjà une instance lancé !" & VbCrLF &_
    CommandLineLike(WScript.ScriptName),VbExclamation,"Attention ! Il ya déjà une instance lancé !"    
    WScript.Quit   
Else 
Dim fso,ws,MonDossier,File,MyNewFile
set ws = CreateObject("wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
MonDossier = Parcourir_Dossier()
Set MonDossier = fso.GetFolder(MonDossier)
For each File in MonDossier.Files
    MyNewFile = Replace(File," ","_") '<--------------- Ligne remplacement texte
    MyNewFile = GetNameFile(MyNewFile)
    Call RenameMyFile(File,MyNewFile)
Next
MsgBox "Done !",VbInformation,"L'opération est finie"
ws.run "explorer.exe "& DblQuote(MonDossier)
End If
'*********************************************************************************************
Function Parcourir_Dossier()
    Dim objShell,objFolder,Message
    Message = "Veuillez choisir un dossier :"
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder(0,Message,1,"C:\Moi\Docs")
    If objFolder Is Nothing Then
        Wscript.Quit
    End If
    Parcourir_Dossier = objFolder.self.path
end Function
'*********************************************************************************************
Function GetNameFile(sFile)
    Dim  Tab
    Tab = Split(sFile,"\")
    GetNameFile = Tab(UBound(Tab))
End Function
'*********************************************************************************************
Sub RenameMyFile(File1,File2)
    Dim Ws,Command,Execution
    Set Ws = CreateObject("WScript.Shell")
    Command = "Cmd /c Rename "& DblQuote(File1) &" "& DblQuote(File2) &""
    Execution = Ws.Run(Command,0,False)
End Sub
'*********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************************
Function AppPrevInstance()   
    With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")   
        With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
            " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")   
            AppPrevInstance = (.Count > 1)
        End With   
    End With   
End Function    
'*********************************************************************************************
Function CommandLineLike(ProcessPath)   
    ProcessPath = Replace(ProcessPath, "\", "\\")   
    CommandLineLike = "'%" & ProcessPath & "%'"   
End Function
'*********************************************************************************************

Merci d’avance pour votre aide