我的知识记录

压缩文件修改日期怎么改 录音文件修改日期怎么改

压缩文件和录音文件修改日期的方法

Windows 系统

PowerShell 方法(推荐):


 
powershell
# 修改压缩文件的修改时间 (Get-Item "C:\Archives\archive.zip").LastWriteTime = "2024-06-15 14:30:00" (Get-Item "C:\Documents\backup.rar").LastWriteTime = "2024-06-10 09:15:00" # 修改录音文件的修改时间 (Get-Item "C:\Recordings\meeting.wav").LastWriteTime = "2024-06-15 14:30:00" (Get-Item "C:\Audio\interview.mp3").LastWriteTime = "2024-06-12 10:30:00" # 批量修改压缩文件 Get-ChildItem "C:\Archives" -Include "*.zip","*.rar","*.7z" | ForEach-Object { $_.LastWriteTime = "2024-06-15 14:30:00" } # 批量修改录音文件 Get-ChildItem "C:\Recordings" -Include "*.wav","*.mp3","*.m4a","*.flac" -Recurse | ForEach-Object { $_.LastWriteTime = "2024-06-15 14:30:00" }

CMD 命令行方法:


 
cmd
# 修改单个压缩文件时间 powershell "(Get-Item 'C:\Archives\archive.zip').LastWriteTime = '2024-06-15 14:30:00'" # 修改单个录音文件时间 powershell "(Get-Item 'C:\Recordings\meeting.wav').LastWriteTime = '2024-06-15 14:30:00'"

Linux/macOS 系统

使用 touch 命令:


 
bash
# 修改压缩文件的修改时间 touch -m -t 202406151430 /path/to/archives/archive.zip touch -m -t 202406100915 /path/to/documents/backup.rar # 修改录音文件的修改时间 touch -m -t 202406151430 /path/to/recordings/meeting.wav touch -m -t 202406121030 /path/to/audio/interview.mp3 # 批量修改压缩文件 find /path/to/archives \( -name "*.zip" -o -name "*.rar" -o -name "*.7z" \) -exec touch -m -t 202406151430 {} \; # 批量修改录音文件 find /path/to/recordings \( -name "*.wav" -o -name "*.mp3" -o -name "*.m4a" -o -name "*.flac" \) -exec touch -m -t 202406151430 {} \;

编程方式修改

Python 方法:


 
python
import os import time from datetime import datetime def change_file_modification_time(file_path, year, month, day, hour, minute, second=0): """ 修改文件的修改时间 :param file_path: 文件路径 :param year, month, day, hour, minute, second: 时间参数 """ try: # 创建 datetime 对象 new_time = datetime(year, month, day, hour, minute, second) # 转换为时间戳 timestamp = time.mktime(new_time.timetuple()) # 修改文件时间 os.utime(file_path, (timestamp, timestamp)) print(f"成功修改 {file_path} 的修改时间为 {new_time}") return True except Exception as e: print(f"修改失败: {e}") return False # 修改压缩文件时间 change_file_modification_time("archive.zip", 2024, 6, 15, 14, 30) change_file_modification_time("/path/to/backup.rar", 2024, 6, 10, 9, 15) # 修改录音文件时间 change_file_modification_time("meeting.wav", 2024, 6, 15, 14, 30) change_file_modification_time("/path/to/interview.mp3", 2024, 6, 12, 10, 30)

批量处理脚本:


 
python
import os import glob from datetime import datetime def batch_modify_file_times(directory, patterns, target_datetime): """ 批量修改文件时间 :param directory: 目录路径 :param patterns: 文件模式列表 :param target_datetime: 目标时间 """ timestamp = time.mktime(target_datetime.timetuple()) for pattern in patterns: search_pattern = os.path.join(directory, pattern) files = glob.glob(search_pattern) for file_path in files: try: os.utime(file_path, (timestamp, timestamp)) print(f"已修改: {file_path}") except Exception as e: print(f"修改失败 {file_path}: {e}") # 批量修改压缩文件 compress_patterns = ["*.zip", "*.rar", "*.7z", "*.tar.gz"] compress_time = datetime(2024, 6, 15, 14, 30) batch_modify_file_times("/path/to/archives", compress_patterns, compress_time) # 批量修改录音文件 audio_patterns = ["*.wav", "*.mp3", "*.m4a", "*.flac"] audio_time = datetime(2024, 6, 15, 14, 30) batch_modify_file_times("/path/to/recordings", audio_patterns, audio_time)

支持的常见文件格式

压缩文件格式:

  • .zip - ZIP 压缩文件
  • .rar - RAR 压缩文件
  • .7z - 7-Zip 压缩文件
  • .tar - TAR 归档文件
  • .tar.gz 或 .tgz - GZIP 压缩的 TAR 文件
  • .tar.bz2 - BZIP2 压缩的 TAR 文件
  • .gz - GZIP 压缩文件

录音文件格式:

  • .wav - WAV 音频文件
  • .mp3 - MP3 音频文件
  • .m4a - M4A 音频文件
  • .flac - FLAC 无损音频文件
  • .aac - AAC 音频文件
  • .wma - WMA 音频文件
  • .ogg - OGG 音频文件
  • .opus - Opus 音频文件

实用批处理脚本

Windows PowerShell 脚本:


 
powershell
# 批量修改多种文件的时间 $compressionFiles = Get-ChildItem "C:\Archives" -Include "*.zip","*.rar","*.7z" $audioFiles = Get-ChildItem "C:\Recordings" -Include "*.wav","*.mp3","*.m4a","*.flac" -Recurse $targetDate = Get-Date "2024-06-15 14:30:00" foreach ($file in $compressionFiles) { $file.LastWriteTime = $targetDate Write-Host "已修改压缩文件: $($file.Name)" } foreach ($file in $audioFiles) { $file.LastWriteTime = $targetDate Write-Host "已修改录音文件: $($file.Name)" }

Linux Bash 脚本:


 
bash
#!/bin/bash # 设置目标时间 TARGET_TIME="202406151430" # 修改压缩文件时间 echo "修改压缩文件时间..." find /path/to/archives -type f \( \ -name "*.zip" -o \ -name "*.rar" -o \ -name "*.7z" -o \ -name "*.tar.gz" -o \ -name "*.tar.bz2" \) \ -exec touch -m -t $TARGET_TIME {} \; # 修改录音文件时间 echo "修改录音文件时间..." find /path/to/recordings -type f \( \ -name "*.wav" -o \ -name "*.mp3" -o \ -name "*.m4a" -o \ -name "*.flac" \) \ -exec touch -m -t $TARGET_TIME {} \; echo "所有文件时间修改完成"

注意事项

  1. 文件内容不受影响:修改时间属性不会改变文件的实际内容
  2. 权限检查:确保对目标文件有写入权限
  3. 系统文件保护:某些系统文件可能受到保护,无法修改时间
  4. 时区考虑:时间修改会受到本地时区设置影响
  5. 备份建议:批量操作前建议备份重要文件
  6. 云同步注意:云存储服务可能会覆盖手动修改的时间属性
这些方法适用于所有类型的文件,包括压缩文件和录音文件。选择最适合您的操作系统和使用习惯的方法即可。
 

压缩文件修改日期怎么改 录音文件修改日期怎么改

标签:

更新时间:2025-12-13 16:10:52

上一篇:压缩文件修改日期怎么改 录音文件修改日期怎么改

下一篇:doc上传日期修改 word文件修改日期