批处理修改文档最后保存时间(图文)
以下是使用批处理修改文档最后保存时间的方法:
方法一:使用PowerShell脚本
基本语法:
powershell
# 修改单个文件的最后修改时间 $file = Get-Item "C:\path\to\your\document.docx" $file.LastWriteTime = "2024-01-01 15:30:00" # 修改单个文件的创建时间 $file.CreationTime = "2024-01-01 15:30:00" # 修改单个文件的最后访问时间 $file.LastAccessTime = "2024-01-01 15:30:00"批量修改多个文件:
powershell
# 修改指定文件夹下所有Word文档的最后修改时间 Get-ChildItem "C:\Documents\*.docx" | ForEach-Object { $_.LastWriteTime = "2024-01-01 15:30:00" }方法二:使用批处理命令(.bat文件)
基本批处理脚本:
batch
@echo off REM 修改单个文件的时间戳 copy /b document.docx +,, >nul powershell "$(Get-Item 'document.docx').LastWriteTime = '2024-01-01 15:30:00'" pause批量修改文件时间:
batch
@echo off REM 修改当前目录下所有Word文档的时间戳 for %%f in (*.docx) do ( powershell "$file = Get-Item '%%f'; $file.LastWriteTime = '2024-01-01 15:30:00'" ) echo 所有文档的时间戳已更新 pause方法三:高级PowerShell脚本
按条件批量修改:
powershell
# 修改指定日期范围内的文件 Get-ChildItem "C:\Documents" -Recurse -File | Where-Object { $_.LastWriteTime -ge "2023-01-01" -and $_.LastWriteTime -le "2023-12-31" } | ForEach-Object { $_.LastWriteTime = "2024-01-01 15:30:00" Write-Host "Updated: $($_.Name)" }交互式脚本:
powershell
# 用户输入目标时间和文件路径 $targetTime = Read-Host "请输入目标时间 (格式: YYYY-MM-DD HH:MM:SS)" $folderPath = Read-Host "请输入文件夹路径" $fileExtension = Read-Host "请输入文件扩展名 (如: .docx)" Get-ChildItem "$folderPath\$fileExtension" | ForEach-Object { $_.LastWriteTime = $targetTime Write-Host "已更新: $($_.Name) -> $targetTime" }方法四:使用第三方工具配合批处理
Touch命令工具:
batch
@echo off REM 需要先下载touch.exe工具 for %%f in (*.docx) do ( touch -t 202401011530 %%f )实用批处理模板
完整的文档时间修改工具:
batch
@echo off title 文档时间修改工具 color 0A :menu cls echo ================================ echo 文档时间修改工具 echo ================================ echo 1. 修改单个文件时间 echo 2. 批量修改Word文档时间 echo 3. 批量修改Excel文档时间 echo 4. 批量修改所有文档时间 echo 5. 退出 echo ================================ set /p choice=请选择操作: if "%choice%"=="1" goto single_file if "%choice%"=="2" goto batch_word if "%choice%"=="3" goto batch_excel if "%choice%"=="4" goto batch_all if "%choice%"=="5" exit goto menu :single_file set /p filepath=请输入文件路径: set /p newtime=请输入新时间 (YYYY-MM-DD HH:MM:SS): powershell "$file = Get-Item '%filepath%'; $file.LastWriteTime = '%newtime%'" echo 文件时间已更新 pause goto menu :batch_word set /p folder=请输入文件夹路径: set /p newtime=请输入新时间 (YYYY-MM-DD HH:MM:SS): powershell "Get-ChildItem '%folder%\*.docx' | ForEach-Object {$_.LastWriteTime = '%newtime%'}" echo Word文档时间已批量更新 pause goto menu :batch_excel set /p folder=请输入文件夹路径: set /p newtime=请输入新时间 (YYYY-MM-DD HH:MM:SS): powershell "Get-ChildItem '%folder%\*.xlsx' | ForEach-Object {$_.LastWriteTime = '%newtime%'}" echo Excel文档时间已批量更新 pause goto menu :batch_all set /p folder=请输入文件夹路径: set /p newtime=请输入新时间 (YYYY-MM-DD HH:MM:SS): powershell "Get-ChildItem '%folder%\*' -Include *.docx,*.xlsx,*.pptx,*.pdf | ForEach-Object {$_.LastWriteTime = '%newtime%'}" echo 所有文档时间已批量更新 pause goto menu注意事项
- 执行脚本可能需要管理员权限
- 某些安全策略可能阻止PowerShell脚本执行
- 建议在运行前备份重要文件
- 时间格式必须严格按照要求输入
- 批量操作前建议先测试单个文件

更新时间:2025-12-18 13:50:27
