I'm about to change the file name of a lot of files and i found this script. I have modified it a bit but the prob is that it renames the first file to A10001.vbs the second to A10001_.vbs the third to A10002.vbs, forth A10002_.vbs
If i remove the last part in the script it only ren one file in the dir. What i'm looking for is first file A10001.vbs second A10002.vbs ....
If i remove the last part in the script it only ren one file in the dir. What i'm looking for is first file A10001.vbs second A10002.vbs ....
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='c:\test'} Where " _
& "ResultClass = CIM_DataFile")
IntNumber = 10001
For Each objFile In FileList
strFName = ("A"&IntNumber)
strNewName = objFile.Drive & objFile.Path & _
strFName & "." & "vbs"
strNameCheck = Replace(strNewName, "\", "\\")
i = 1
Do While True
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile Where Name = '" & strNameCheck & "'")
If colFiles.Count = 0 Then
errResult = objFile.Rename(strNewName)
Exit Do
Else
IntNumber = IntNumber + 1
i = i + 1
strNewName = objFile.Drive & objFile.Path & _
strFName & "_" & "." & "vbs"
strNameCheck = Replace(strNewName, "\", "\\")
End If
Loop
Next