ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
12
返回列表 发新帖
楼主: ning84

QQ“发到我的电脑”图片更改文件日期,如何恢复正确日期。

[复制链接]

TA的精华主题

TA的得分主题

 楼主| 发表于 2024-4-10 10:30 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
修改文件、文件夹的创建时间、修改时间_shell 获取文件创建时间-CSDN博客  https://blog.csdn.net/tangyin025/article/details/128764302


看了这个帖子有点思路。能走到这步,应该目标可以实现。

image.png


image.png


TA的精华主题

TA的得分主题

 楼主| 发表于 2024-4-12 07:00 | 显示全部楼层
学习学习在学习。

https://github.com/MicrosoftDocs ... ll/shell-settime.md

xamples
The following example shows SetTime in use. Proper usage is shown for JScript, VBScript, and Visual Basic.

JScript:

<script language="JScript">
    function fnShellSetTimeJ()
    {
        var objShell = new ActiveXObject("shell.application");
        
        objShell.SetTime();
    }
</script>
VBScript:

<script language="VBScript">
    function fnShellSetTimeVB()
        dim objShell
        
        set objShell = CreateObject("shell.application")
        objShell.SetTime

        set objShell = nothing
    end function
</script>
Visual Basic:

Private Sub fnShellSetTimeVB()
    Dim objShell As Shell
   
    Set objShell = New Shell
    objShell.SetTime

    Set objShell = Nothing
End Sub
Requirements
Requirement        Value
Minimum supported client
Windows 2000 Professional, Windows XP [desktop apps only]
Minimum supported server
Windows 2000 Server [desktop apps only]
Header
Shldisp.h
IDL
Shldisp.idl
DLL
Shell32.dll (version 4.71 or later)

TA的精华主题

TA的得分主题

 楼主| 发表于 2024-4-13 13:40 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

越学越 深,还是没有达到目标需求,更改文件的时间。

https://wenda.so.com/q/166022343 ... 6%E6%97%B6%E9%97%B4



image.png



  1. Private Type FILETIME '结构体声明
  2. dwLowDateTime As Long
  3. dwHighDateTime As Long
  4. End Type
  5. Private Type SYSTEMTIME
  6. wYear As Integer
  7. wMonth As Integer
  8. wDayOfWeek As Integer
  9. wDay As Integer
  10. wHour As Integer
  11. wMinute As Integer
  12. wSecond As Integer
  13. wMilliseconds As Integer
  14. End Type
  15. Private Const GENERIC_WRITE = &H40000000 '常数声明
  16. Private Const OPEN_EXISTING = 3
  17. Private Const FILE_SHARE_READ = &H1
  18. Private Const FILE_SHARE_WRITE = &H2

  19. 'API声明
  20. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  21. Private Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
  22. Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
  23. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  24. Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime As FILETIME, lpFileTime As FILETIME) As Long

  25. Private Sub Command1_Click()
  26. Dim lngHandle As Long
  27. Dim udtFileTime As FILETIME
  28. Dim udtLocalTime As FILETIME
  29. Dim udtSystemTime As SYSTEMTIME

  30. '这里把C:\***.xls设置成2008年8月8日
  31. '***.wyear = 2008 '设年
  32. ''***.wmonth = 8 '月"
  33. '***.wday = 8 '日
  34. '***.wdayofweek = 0 '周
  35. '***.whour = 0 '时
  36. '***.wminute = 0 '分
  37. '***.wsecond = 0 '秒
  38. '***.wmilliseconds = 0 '毫秒

  39. ' 转换时间格式 ,不知道微软为什么要搞得这么麻烦
  40. SystemTimeToFileTime udtSystemTime, udtLocalTime
  41. ' 再转换
  42. LocalFileTimeToFileTime udtLocalTime, udtFileTime

  43. ' createfile在这里不是创建,是打开要修改的文件C:\***.xls
  44. lngHandle = CreateFile("C:\***.xls", GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)

  45. ' 改变文件时间并msgbox结果
  46. MsgBox SetFileTime(lngHandle, udtFileTime, udtFileTime, udtFileTime)
  47. ' 关掉句柄
  48. CloseHandle lngHandle

  49. End Sub
复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2024-4-14 14:36 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册




学习学习再学习,一个一个帖子试。


VB如何修改文件的创建时间?-CSDN社区  https://bbs.csdn.net/topics/70403822


  1. Public Type FILETIME
  2. dwLowDateTime As Long
  3. dwHighDateTime As Long
  4. End Type
  5. Public Const OFS_MAXPATHNAME = 128
  6. Public Type OFSTRUCT
  7. cBytes As Byte
  8. fFixedDisk As Byte
  9. nErrCode As Integer
  10. Reserved1 As Integer
  11. Reserved2 As Integer
  12. szPathName(OFS_MAXPATHNAME) As Byte
  13. End Type
  14. Public Const OF_READ = &H0
  15. Public Const OF_READWRITE = &H2
  16. Public Type SYSTEMTIME
  17. wYear As Integer
  18. wMonth As Integer
  19. wDayOfWeek As Integer
  20. wDay As Integer
  21. wHour As Integer
  22. wMinute As Integer
  23. wSecond As Integer
  24. wMilliseconds As Integer
  25. End Type
  26. Public Type TIME_ZONE_INFORMATION
  27. bias As Long
  28. StandardName(32) As Integer
  29. StandardDate As SYSTEMTIME
  30. StandardBias As Long
  31. DaylightName(32) As Integer
  32. DaylightDate As SYSTEMTIME
  33. DaylightBias As Long
  34. End Type
  35. Public Type BY_HANDLE_FILE_INFORMATION
  36. dwFileAttributes As Long
  37. ftCreationTime As FILETIME
  38. ftLastAccessTime As FILETIME
  39. ftLastWriteTime As FILETIME
  40. dwVolumeSerialNumber As Long
  41. nFileSizeHigh As Long
  42. nFileSizeLow As Long
  43. nNumberOfLinks As Long
  44. nFileIndexHigh As Long
  45. nFileIndexLow As Long
  46. End Type
  47. Public Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
  48. Public Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
  49. Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  50. Public Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
  51. Public Declare Function SetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
  52. Public Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
  53. Public Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
  54. Dim FileHandle As Long
  55. Dim OpenBuff As OFSTRUCT
  56. Dim tZone As TIME_ZONE_INFORMATION
  57. Dim sCreate As SYSTEMTIME
  58. Dim sAccess As SYSTEMTIME
  59. Dim sWrite As SYSTEMTIME
  60. Dim fCreate As FILETIME
  61. Dim fAccess As FILETIME
  62. Dim fWrite As FILETIME
  63. Dim bias As Long
  64. Dim theTime As Date
  65. Dim FileInfo As BY_HANDLE_FILE_INFORMATION
  66. Public Enum FileTimeOptions
  67. theCreateTime = 1
  68. theLastAccessTime = 2
  69. theLastWriteTime = 3
  70. End Enum

  71. Public Sub SetTime(ByVal FileName As String, ByVal CreateTime As Date, ByVal LastAccessTime As Date, ByVal LastWriteTime As Date)

  72. '1,处理文件属性,去掉只读等属性,
  73. If Dir(FileName, 63) = "" Then Exit Sub
  74. SetAttr FileName, vbNormal

  75. '2,处理时差
  76. GetTimeZoneInformation tZone
  77. bias = tZone.bias '时差,以分钟为单位,中国地区为早8小时,值-480。
  78. theTime = TimeSerial(0, bias, 0)
  79. CreateTime = CreateTime + theTime
  80. LastAccessTime = LastAccessTime + theTime
  81. LastWriteTime = LastWriteTime + theTime

  82. '3,将SYSTEMTIME格式时间转换为FILETIME格式时间
  83. sCreate.wDay = Day(CreateTime): sCreate.wHour = Hour(CreateTime): sCreate.wMinute = Minute(CreateTime): sCreate.wMonth = Month(CreateTime): sCreate.wSecond = Second(CreateTime): sCreate.wYear = Year(CreateTime)
  84. sAccess.wDay = Day(LastAccessTime): sAccess.wHour = Hour(LastAccessTime): sAccess.wMinute = Minute(LastAccessTime): sAccess.wMonth = Month(LastAccessTime): sAccess.wSecond = Second(LastAccessTime): sAccess.wYear = Year(LastAccessTime)
  85. sWrite.wDay = Day(LastWriteTime): sWrite.wHour = Hour(LastWriteTime): sWrite.wMinute = Minute(LastWriteTime): sWrite.wMonth = Month(LastWriteTime): sWrite.wSecond = Second(LastWriteTime): sWrite.wYear = Year(LastWriteTime)
  86. SystemTimeToFileTime sCreate, fCreate
  87. SystemTimeToFileTime sAccess, fAccess
  88. SystemTimeToFileTime sWrite, fWrite

  89. '4,修改文件时间
  90. FileHandle = OpenFile(FileName, OpenBuff, OF_READWRITE)
  91. SetFileTime FileHandle, fCreate, fAccess, fWrite '注:这里的三个时间采用的是格林尼治标准时间!
  92. CloseHandle FileHandle

  93. End Sub
  94. Public Function GetTime(ByVal FileName As String, Optional ByVal TimeOfFile As FileTimeOptions = theCreateTime) As Date
  95. If Dir(FileName, 63) = "" Then Exit Function
  96. FileHandle = OpenFile(FileName, OpenBuff, OF_READ)
  97. GetFileInformationByHandle FileHandle, FileInfo
  98. CloseHandle FileHandle
  99. GetTimeZoneInformation tZone
  100. bias = tZone.bias
  101. FileTimeToSystemTime FileInfo.ftCreationTime, sCreate
  102. FileTimeToSystemTime FileInfo.ftLastAccessTime, sAccess
  103. FileTimeToSystemTime FileInfo.ftLastWriteTime, sWrite

  104. Dim CurTime As SYSTEMTIME
  105. Select Case TimeOfFile
  106. Case 1


  107. CurTime = sCreate
  108. Case 2
  109. CurTime = sAccess
  110. Case 3
  111. CurTime = sWrite
  112. End Select
  113. GetTime = DateSerial(CurTime.wYear, CurTime.wMonth, CurTime.wDay) + TimeSerial(CurTime.wHour, CurTime.wMinute - bias, CurTime.wSecond)

  114. End Function



  115. Sub ll()
  116.    
  117.    Dim oDate1 As Date, oDate2 As Date, oDate3 As Date
  118.    oDate1 = "1939/1/1"
  119.    oDate2 = "1949/1/1"
  120.    oDate3 = "1959/1/1"
  121.    SetTime "c:\1.jpg", oDate1, oDate2, oDate3
  122.    
  123.    
  124. End Sub

复制代码


TA的精华主题

TA的得分主题

 楼主| 发表于 2024-4-15 15:58 | 显示全部楼层
继续复习以前学习到的知识。
https://learn.microsoft.com/zh-c ... redirectedfrom=MSDN
Folder.ParseName 方法 (Shldisp.h) - Win32 apps | Microsoft Learn  https://learn.microsoft.com/zh-c ... redirectedfrom=MSDN
GetDetailsOf


  1. Private Sub btnParseName_Click()
  2.     Dim objShell  As Shell
  3.     Dim objFolder As Shell32.Folder    'ShellFolderItem
  4.     Dim objFolderItem As Shell32.FolderItem

  5.     Set objShell = New Shell
  6.     Set objFolder = objShell.Namespace("F:")
  7.   
  8.     If (Not objFolder Is Nothing) Then
  9.         'Dim objFolderItem As FolderItem
  10.         
  11.         Set objFolderItem = objFolder.ParseName("IMG_20240415_081120712.jpg")
  12.         
  13.         
  14.        Debug.Print objFolder.GetDetailsOf(objFolderItem, 3)
  15.        Debug.Print objFolder.GetDetailsOf(objFolderItem, 4)
  16.        Debug.Print objFolder.GetDetailsOf(objFolderItem, 5)
  17.       
  18.         
  19.        ' Set tmpFile = oFolder.ParseName(ImgName)
  20.             'Add code here.
  21.             Debug.Print objFolderItem.ModifyDate
  22.         Set objFolderItem = Nothing
  23.     End If

  24.     Set objFolder = Nothing
  25.     Set objShell = Nothing
  26. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2024-4-17 11:03 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
猴子掰苞米,边学边忘,还是整理以前学习到的相关知识。


ExtendedProperty("System.Photo.DateTaken")结果相差8小时.-Excel VBA程序开发-ExcelHome技术论坛 -  https://club.excelhome.net/thread-1666398-1-1.html

  1. Private Sub dell11()
  2.    
  3.    
  4.    Dim oSh As Shell32.Shell
  5.    Dim ImgName
  6.    Dim oFolder As Shell32.Folder
  7.        Set oSh = New Shell32.Shell

  8.    Dim FolderIt As ShellFolderItem
  9.    Dim Str
  10.    Dim oDir
  11.    Dim oDate As Date
  12.        oDir = "F:"
  13.       
  14.       
  15.        ImgName = "F:\4.jpg"
  16.        ImgName = "4.jpg"
  17.        Set oFolder = oSh.Namespace(oDir)
  18.        Set tmpFile = oFolder.ParseName(ImgName)
  19.        Str = oFolder.GetDetailsOf(tmpFile, 12)
  20.        Str = Replace(Str, ChrW(8206), "")
  21.        Str = Replace(Str, ChrW(8207), "")
  22.        Debug.Print Str
  23.       
  24.        Set FolderIt = oSh.Namespace(oDir).ParseName(ImgName)
  25.        With FolderIt
  26.           Debug.Print .ExtendedProperty("System.Photo.DateTaken")
  27.           Debug.Print .ModifyDate
  28.        End With
  29.       
  30.        'Debug.Print oDate
  31.    Dim Fso As FileSystemObject, tFile As File
  32.        Set Fso = New FileSystemObject
  33.        Set tFile = Fso.GetFile("F:\4.jpg")
  34.        With tFile
  35.            Debug.Print .DateCreated, .DateLastAccessed, .DateLastModified
  36.        End With
  37.    Dim Img As WIA.ImageFile
  38.        Set Img = New WIA.ImageFile
  39.        Img.LoadFile "F:\4.jpg"
  40.        With Img
  41.             aa = Split(.Properties(4), " ")
  42.             Str = Replace(aa(0), ":", "/") & " " & aa(1)
  43.             oDate = Str
  44.             Debug.Print Str
  45.        End With

  46. End Sub
复制代码


?2023/?6/?14 ??16:24不能转换为日期型.-Excel VBA程序开发-ExcelHome技术论坛 -  https://club.excelhome.net/thread-1666047-1-1.html

  1. Sub d()
  2.    Dim oSh As Shell32.Shell
  3.    Dim Img, ImgName
  4.    Dim oFolder As Shell32.Folder
  5.        Set oSh = New Shell32.Shell
  6.    
  7.    Dim oDir, oFile
  8.    Dim oDate As Date
  9.        oDir = "F:"
  10.        Set oFolder = oSh.Namespace(oDir)
  11.        ImgName = "4.jpg"
  12.        Set Img = oFolder.ParseName(ImgName)
  13.        Debug.Print oFolder.GetDetailsOf(ImgName, 12), oFolder.GetDetailsOf(Img, 12)
  14.        oDate = Img.ExtendedProperty("System.Photo.DateTaken")
  15.    Debug.Print oDate
  16.        Stop
  17.       
  18. End Sub
复制代码




您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-17 15:38 , Processed in 0.037920 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表