使用 FileSystemObject 将图像文件重写到具有更新修改日期的目录?

Use FileSystemObject to rewrite image file to directory with updated Modified Date?

FileSystemObject 命令CopyFile 将获取任何文件并制作一份副本,但它会保留修改日期不变。有没有办法打开现有图像(JPG、PNG 等)文件并将其 "write" 改为目录(两步过程?),这会导致修改日期发生变化?我知道 FileSystemObject 可以用文本文件做到这一点,但不确定是否有办法用 JPG 或 PNG 做到这一点。

你可以这样做:

  1. 使用 FileSystemObject.CopyFile
  2. 复制您的文件
  3. "Touch"复制的文件,具有本问题中提供的功能:

    Sub touch(strDir, strFileName, DateTime)
        Dim objShell, objFolder
        Set objShell = CreateObject("Shell.Application")
        Set objFolder = objShell.NameSpace(strDir)
        objFolder.Items.Item(strFileName).ModifyDate = DateTime
    End Sub
    

... 将当前日期传递给 touch():

touch strDir, strFileName, Now