I am trying to rename files in folders with the name of the folders in which they reside, the date and time and some other things. I would like the time to read 05.03.22 AM and it's coming up 5.3.22 AM here's the code, can someone assist with the time portion?
Thanks
Thanks
Code:
Call RenameAllFiles("C:\Test")
Sub RenameAllFiles(strFolder)
Dim fso, file, folder
Set fso = CreateObject("Scripting.FileSystemObject")
' Check for AVIs to rename.
For Each file in fso.GetFolder(strFolder).Files
'If Right(file.Name, 4) = ".avi" Then
Call RenameFile(strFolder & "\" & file.Name)
'End If
Next
' Check for SubFolders to recurse into.
For Each folder in fso.GetFolder(strFolder).SubFolders
Call RenameAllFiles(strFolder & "\" & folder.Name)
Next
End Sub
Sub RenameFile(strFileName)
Dim fso, strExt, strFolder, strNewFileName, t, p, f
Set fso = CreateObject("Scripting.FileSystemobject")
t = Month(Date) & "." & Day(Date) & "." & Year(Date) & " " & Hour(Time) & "." & Minute(Time) & "." & Second(Time)
p = "_PPW-OFU_"
f = fso.GetFileName(strFileName)
' Note the extension (should be avi)
strExt = fso.GetExtensionName(strFileName)
' Derive the full path to the folder.
strFolder = fso.GetParentFolderName(strFileName)
' Derive the new filename.
strNewFileName = strFolder & "\" & t & p & fso.GetBaseName(strFolder) & "-" & f '& "." & strExt
' Do the rename.
If strFileName <> strNewFileName Then
WScript.Echo "Renaming " & strFileName & " to " & strNewFileName
fso.MoveFile strFileName, strNewFileName
End If
End Sub