更新时间:2022-11-17 16:16:35
如果您想根据上次修改日期进行覆盖,则 File 对象具有您想要的属性:DateLastModified代码>.(您可以检查
File
对象的所有属性 此处.)
If you want to overwrite based on the last modified date, then the File
object has the property you want: DateLastModified
. (You can check all properties of the File
object here.)
您已经可以访问源文件对象(您的代码的 Photo
变量),因此您只需要获取目标的文件对象.
You already have access to the source file objects (your code's Photo
variable) so you just need to get the target's file object.
这样的事情应该可以工作:
Something like this should work:
Dim Photo
Dim targetFile, bmpTargetFilename, jpgTargetFilename
SourceFolder = "C:\Photo1"
DistinationFolder = "C:\Photo2"
Set ObjPhoto = CreateObject("Scripting.FileSystemObject")
For Each Photo In ObjPhoto.GetFolder(SourceFolder).Files
bmpTargetFilename = ObjPhoto.BuildPath(DistinationFolder, Replace(Photo.Name, ".jpg", ".bmp"))
jpgTargetFilename = ObjPhoto.BuildPath(DistinationFolder, Photo.Name)
If ObjPhoto.FileExists(bmpTargetFilename) Then
' Get the target file object
Set targetFile = ObjPhoto.GetFile(jpgTargetFilename)
' Now compare the last modified dates of both files
If Photo.DateLastModified > targetFile.DateLastModified Then
Photo.Copy jpgTargetFilename, True
End If
Else
Photo.Copy jpgTargetFilename, True
End If
Next
一些注意事项: