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," ","_")
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)
End If
'*********************************************************************************************
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
'*********************************************************************************************
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
'********************************************************************************************* |
Partager