Hi,
I was trying to create a script that renames .jpg files based on the last modified date. I found a script at microsofts scriptcenter:
But this script renames all files in the specified folder and based on the creation date. Could you give me some suggestions to modify this script or how to make a new one that rename my jpg files based on the last modified date.
I was trying to create a script that renames .jpg files based on the last modified date. I found a script at microsofts scriptcenter:
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='e:\bilder\test'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
strDate = Left(objFile.CreationDate, 12)
strNewName = objFile.Drive & objFile.Path & _
strDate & "." & "jpg"
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
i = i + 1
strNewName = objFile.Drive & objFile.Path & _
strDate & "_" & i & "." & "jpg"
strNameCheck = Replace(strNewName, "\", "\\")
End If
Loop
Next