I wrote this VBS code to copy "Date Modified" from files in one folder to another folder.
Dim sOriginFolder, sDestinationFolder, sFile, oFSO, oShell
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace("C:\Users\asd\Desktop\Destination")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Wscript.Shell")
sOriginFolder = "C:\Users\asd\Desktop\Source"
sDestinationFolder = "C:\Users\asd\Desktop\Destination"
For Each sFile In oFSO.GetFolder(sOriginFolder).Files
Set objFolderItem = objFolder.ParseName(oFSO.GetFileName(sFile))
objFolderItem.ModifyDate = FormatDateTime(sFile.DateLastModified,0)
Next
It works but there is one issue. If the extension of the file is different, then the script crashes.
How can I fix this?
But if the extensions are different, then the program crashes with 'type mismatch'.
– user5793353 Apr 16 '19 at 05:34