如何更改文档修改时间(图文)
文档修改时间是指文件系统记录的"最后修改时间",可以通过多种方法进行更改。
Windows系统修改方法
1. 使用PowerShell(推荐)
powershell
# 修改单个文件的修改时间 $filePath = "C:\path\to\your\document.docx" $(Get-Item $filePath).LastWriteTime = "2023-12-01 15:30:00" # 修改多个文件的修改时间 $files = Get-ChildItem -Path "C:\Documents" -Include *.docx,*.xlsx,*.pdf foreach ($file in $files) { $file.LastWriteTime = "2023-12-01 15:30:00" Write-Output "已修改: $($file.Name)" }2. 使用命令提示符(需要第三方工具)
首先下载安装touch命令工具,然后执行:
cmd
touch -m -t 202312011530 document.docx3. 批处理脚本
batch
@echo off setlocal enabledelayedexpansion REM 修改单个文件 powershell "$(Get-Item 'document.docx').LastWriteTime = '2023-12-01 15:30:00'" REM 批量修改文件 for %%f in (*.docx *.xlsx *.pdf) do ( powershell "$(Get-Item '%%f').LastWriteTime = '2023-12-01 15:30:00'" echo 已修改: %%f )macOS系统修改方法
使用终端命令
bash
# 修改单个文件的修改时间 touch -m -t 202312011530 /path/to/document.docx # 批量修改文件 find /path/to/documents -name "*.docx" -exec touch -m -t 202312011530 {} \;Linux系统修改方法
使用touch命令
bash
# 修改文件修改时间 touch -m -d "2023-12-01 15:30:00" /path/to/document.docx # 使用时间戳格式 touch -m -t 202312011530.00 /path/to/document.docx # 批量修改 find /path/to/documents -name "*.docx" -exec touch -m -d "2023-12-01 15:30:00" {} \;跨平台解决方案
使用Python脚本
python
import os import time from datetime import datetime def change_modification_time(file_path, new_time_str): """ 修改文件的最后修改时间 Args: file_path (str): 文件路径 new_time_str (str): 新的时间字符串,格式如 "2023-12-01 15:30:00" """ try: # 将时间字符串转换为时间戳 new_time = datetime.strptime(new_time_str, "%Y-%m-%d %H:%M:%S") timestamp = new_time.timestamp() # 修改文件的访问时间和修改时间 os.utime(file_path, (timestamp, timestamp)) print(f"成功修改文件修改时间: {file_path}") return True except Exception as e: print(f"修改失败: {e}") return False def batch_change_modification_time(directory, extensions=None, new_time_str="2023-12-01 15:30:00"): """ 批量修改目录中文件的修改时间 Args: directory (str): 目录路径 extensions (list): 文件扩展名列表,如 ['.docx', '.xlsx'] new_time_str (str): 新的时间字符串 """ if extensions is None: extensions = ['.docx', '.xlsx', '.pdf', '.txt'] for root, dirs, files in os.walk(directory): for file in files: # 检查文件扩展名 if any(file.lower().endswith(ext) for ext in extensions): file_path = os.path.join(root, file) change_modification_time(file_path, new_time_str) # 使用示例 if __name__ == "__main__": # 修改单个文件 change_modification_time("document.docx", "2023-12-01 15:30:00") # 批量修改文件 batch_change_modification_time("C:/Documents", ['.docx', '.xlsx'], "2023-12-01 15:30:00")使用第三方工具
Windows推荐工具:
- Attribute Changer
- 图形化界面,操作简单
- 支持批量修改
- BulkFileChanger
- 免费工具
- 支持多种时间属性修改
- NewFileTime
- 轻量级工具
- 支持拖拽操作
跨平台工具:
javascript
// Node.js脚本示例 const fs = require('fs'); const path = require('path'); function changeModificationTime(filePath, date) { const timestamp = new Date(date).getTime() / 1000; fs.utimesSync(filePath, timestamp, timestamp); console.log(`Modified: ${filePath}`); } // 使用示例 changeModificationTime('document.docx', '2023-12-01T15:30:00');高级技巧
1. 复制其他文件的时间属性
powershell
# 将source.txt的时间属性复制到target.docx $source = Get-Item "source.txt" $target = Get-Item "target.docx" $target.LastWriteTime = $source.LastWriteTime2. 基于当前时间进行偏移
python
import os from datetime import datetime, timedelta def offset_modification_time(file_path, days=0, hours=0, minutes=0): """基于当前时间进行时间偏移""" current_time = datetime.now() new_time = current_time + timedelta(days=days, hours=hours, minutes=minutes) timestamp = new_time.timestamp() os.utime(file_path, (timestamp, timestamp)) print(f"修改时间为: {new_time}") # 将文件修改时间设置为3天前 offset_modification_time("document.docx", days=-3)注意事项
- 权限要求:确保对文件有写入权限
- 备份文件:重要文件修改前请备份
- 时间格式:严格按照指定格式输入时间
- 系统限制:某些系统可能对时间范围有限制
- 同步影响:云同步服务可能会覆盖修改的时间
- 合法使用:仅在合法合理的场景下使用此功能

更新时间:2025-12-18 10:04:12
上一篇:怎么修改文档时间(图文)
下一篇:怎么修改文档修改时间(图文)
