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
| Option Explicit
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," ","_")
MyNewFile = GetNameFile(MyNewFile)
Call RenameMyFile(File,MyNewFile)
Next
MsgBox "L'oprération est finie !",VbInformation,"L'oprération est finie !"
ws.run "explorer.exe "& DblQuote(MonDossier)
'*********************************************************************************************
Function Parcourir_Dossier()
Dim objShell,objFolder,Message
Message = "Veuillez sélectionner un dossier pour renommer ses fichiers avec underscrore"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0,Message,1,"c:\Programs")
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
'********************************************************************************************* |
Partager