我的知识记录

修改word文档的保存修改时间(图文)

修改Word文档的保存修改时间实际上就是修改文件的最后修改时间戳。以下是几种常用方法:

Windows系统方法

方法1:使用PowerShell(推荐)


 
powershell
# 修改Word文档的修改时间 $filePath = "C:\path\to\your\document.docx" $newModificationTime = Get-Date "2023-12-25 15:30:00" $(Get-Item $filePath).LastWriteTime = $newModificationTime # 验证修改结果 (Get-Item $filePath).LastWriteTime

方法2:使用CMD命令


 
cmd
# 使用copy命令更新时间戳(不改变文件内容) copy /b document.docx+,, # 这会将修改时间更新为当前时间

方法3:使用第三方工具


 
cmd
# 使用nircmd工具(需要下载安装) nircmd.exe setfiletime "document.docx" "25-12-2023 15:30:00" "25-12-2023 15:30:00"

Linux/macOS系统方法

使用touch命令


 
bash
# 修改Word文档的修改时间 touch -m -t 202312251530.00 document.docx # 使用更直观的-d参数 touch -m -d "2023-12-25 15:30:00" document.docx

编程方法修改

Python脚本


 
python
import os import time from datetime import datetime def change_word_doc_time(filepath, new_datetime_str): """ 修改Word文档的修改时间 参数: filepath: Word文档路径 new_datetime_str: 新的时间字符串,如 "2023-12-25 15:30:00" """ try: # 转换时间字符串为时间戳 new_timestamp = time.mktime( datetime.strptime(new_datetime_str, "%Y-%m-%d %H:%M:%S").timetuple() ) # 获取当前文件的访问时间 current_stat = os.stat(filepath) access_time = current_stat.st_atime # 修改文件时间戳(保持访问时间不变) os.utime(filepath, (access_time, new_timestamp)) print(f"成功修改 {filepath} 的修改时间为 {new_datetime_str}") return True except Exception as e: print(f"修改失败: {e}") return False # 使用示例 change_word_doc_time("document.docx", "2023-12-25 15:30:00") # 验证修改结果 def check_file_time(filepath): stat = os.stat(filepath) modification_time = datetime.fromtimestamp(stat.st_mtime) print(f"当前修改时间: {modification_time}") check_file_time("document.docx")

VBA宏方法(在Word中运行)


 
vba
Sub ChangeDocumentSaveTime() ' 注意:此方法只能修改文档属性中的时间,不能修改文件系统时间 Dim doc As Document Set doc = ActiveDocument ' 修改文档属性(这不会改变文件的修改时间) doc.BuiltInDocumentProperties("Creation Date") = "2023-12-25 15:30:00" doc.BuiltInDocumentProperties("Last Save Time") = "2023-12-25 15:30:00" MsgBox "文档属性时间已修改" End Sub

批量修改多个Word文档

PowerShell批量修改


 
powershell
# 批量修改文件夹中所有Word文档的修改时间 $folderPath = "C:\Documents" $wordFiles = Get-ChildItem $folderPath -Include *.doc,*.docx -Recurse $newModTime = Get-Date "2023-12-25 15:30:00" foreach ($file in $wordFiles) { $file.LastWriteTime = $newModTime Write-Host "已修改: $($file.Name)" }

Linux/macOS批量修改


 
bash
# 修改当前目录下所有Word文档的修改时间 find . \( -name "*.doc" -o -name "*.docx" \) -exec touch -m -d "2023-12-25 15:30:00" {} \; # 或者使用循环 for file in *.doc *.docx; do [ -f "$file" ] && touch -m -d "2023-12-25 15:30:00" "$file" && echo "已修改: $file" done

高级技巧

1. 根据参考文件设置时间


 
powershell
# Windows PowerShell $referenceFile = Get-Item "reference.docx" $targetFile = Get-Item "target.docx" $targetFile.LastWriteTime = $referenceFile.LastWriteTime

 
bash
# Linux/macOS touch -m -r reference.docx target.docx

2. 将修改时间设置为当前时间


 
powershell
# Windows $(Get-Item "document.docx").LastWriteTime = Get-Date

 
bash
# Linux/macOS touch -m document.docx

验证修改结果

PowerShell验证


 
powershell
# 查看详细文件信息 Get-Item "document.docx" | Select-Object Name, LastWriteTime, CreationTime, LastAccessTime

CMD验证


 
cmd
dir document.docx

Linux/macOS验证


 
bash
ls -l document.docx stat document.docx

注意事项

  1. 权限要求:确保对目标文件有写入权限
  2. 备份重要文件:操作前建议备份重要文档
  3. 时间格式:注意不同系统接受的时间格式可能不同
  4. 同步软件影响:云同步软件可能会覆盖手动修改的时间戳
  5. Word自动更新:打开并保存Word文档会再次更新修改时间
选择适合您操作系统的方法即可轻松修改Word文档的保存修改时间。
 

修改word文档的保存修改时间(图文)

标签:

更新时间:2025-12-18 10:38:13

上一篇:百度文库上传哪些文档受欢迎(图文)

下一篇:word文档修改保存时间在哪里(图文)