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)


It works but there is one issue. If the extension of the file is different, then the script crashes.

How can I fix this?

  • What extensions does it work on, and what does it not work on? – music2myear Apr 15 at 21:41
  • It takes the first file name from the source folder and takes its date modified. It takes the first file name from the destination folder and if their names match, it pastes the date modified onto it. Then it will take the second file and do the same. But if the extensions are different, then the program crashes with 'type mismatch'. – user5793353 Apr 16 at 5:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.