亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python+PyQt5開發(fā)超全能的文件時(shí)間戳修改器

 更新時(shí)間:2025年06月25日 09:04:07   作者:創(chuàng)客白澤  
在日常開發(fā)中,我們經(jīng)常需要批量修改文件的時(shí)間戳屬性,本文將使用Python的PyQt5庫開發(fā)一個(gè)功能全面的圖形化文件時(shí)間戳編輯器,感興趣的小伙伴可以了解下

概述

在日常開發(fā)中,我們經(jīng)常需要批量修改文件的時(shí)間戳屬性(創(chuàng)建時(shí)間、修改時(shí)間、訪問時(shí)間)。無論是整理照片、管理文檔,還是調(diào)試應(yīng)用程序,時(shí)間戳操作都是一個(gè)常見需求。本文將詳細(xì)介紹如何使用Python的PyQt5庫開發(fā)一個(gè)功能全面的圖形化文件時(shí)間戳編輯器

這個(gè)工具具有以下核心能力:

  • 支持單個(gè)/批量文件操作
  • 三種時(shí)間修改模式:絕對時(shí)間設(shè)置、相對時(shí)間調(diào)整、時(shí)區(qū)轉(zhuǎn)換
  • 跨平臺支持(Windows/macOS/Linux)
  • 現(xiàn)代化的暗色主題界面
  • 批量遞增時(shí)間功能

功能特色

1. 多模式時(shí)間編輯 

  • 絕對時(shí)間設(shè)置:精確設(shè)置到秒級的時(shí)間
  • 相對時(shí)間調(diào)整:支持按小時(shí)、分鐘、秒增減
  • 時(shí)區(qū)轉(zhuǎn)換:全球所有時(shí)區(qū)支持

2. 批量操作能力

  • 文件列表管理(添加/刪除/清空)
  • 批量遞增時(shí)間(按指定間隔自動遞增)

3. 跨平臺兼容性

  • 自動識別操作系統(tǒng)(Windows/macOS/Linux)
  • 針對不同系統(tǒng)適配時(shí)間屬性(Windows支持創(chuàng)建時(shí)間修改)

4. 專業(yè)級UI設(shè)計(jì)

  • 現(xiàn)代化暗色主題
  • 響應(yīng)式布局
  • 實(shí)時(shí)狀態(tài)反饋
  • 標(biāo)簽頁分類管理

效果展示

主界面截圖

批量操作頁面

開發(fā)步驟詳解

1. 環(huán)境準(zhǔn)備

pip install PyQt5 pytz pywin32

2. 項(xiàng)目結(jié)構(gòu)

FileTimeEditor/
│── main.py          # 主程序入口
│── requirements.txt # 依賴文件
└── README.md        # 使用說明

3. 核心開發(fā)流程

3.1 初始化主窗口

class TimeStampEditor(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("文件時(shí)間戳編輯器")
        self.setGeometry(100, 100, 800, 600)
        self.set_dark_theme()  # 設(shè)置暗色主題
        self.init_ui()         # 初始化UI

3.2 實(shí)現(xiàn)暗色主題

def set_dark_theme(self):
    dark_palette = QPalette()
    dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
    dark_palette.setColor(QPalette.WindowText, Qt.white)
    # ...更多顏色設(shè)置
    QApplication.setPalette(dark_palette)

3.3 構(gòu)建主界面

采用QTabWidget實(shí)現(xiàn)標(biāo)簽頁分類:

  • 基本設(shè)置頁
  • 批量操作頁

3.4 文件操作實(shí)現(xiàn)

def add_files(self):
    files, _ = QFileDialog.getOpenFileNames(self, "選擇文件")
    if files:
        for file in files:
            if file not in self.files:
                self.files.append(file)
                self.file_list.addItem(file)

代碼深度解析

1. 時(shí)間處理核心邏輯

def set_file_time(self, file_path, atime=None, mtime=None, ctime=None):
    # 基礎(chǔ)時(shí)間設(shè)置
    if atime_ts is not None or mtime_ts is not None:
        os.utime(file_path, (atime_ts, mtime_ts))
    
    # Windows專屬創(chuàng)建時(shí)間設(shè)置
    if self.system == 'Windows' and ctime:
        import win32file
        wintime = pywintypes.Time(ctime)
        handle = win32file.CreateFile(...)
        win32file.SetFileTime(handle, wintime, None, None)

2. 時(shí)區(qū)轉(zhuǎn)換算法

def convert_timezone(self, target_tz):
    if hasattr(datetime, 'astimezone'):
        # Python 3.3+現(xiàn)代語法
        mtime = mtime.astimezone(target_tz)
    else:
        # 舊版Python兼容處理
        mtime = local_tz.localize(mtime).astimezone(target_tz)

3. 批量遞增時(shí)間實(shí)現(xiàn)

current_time = self.increment_start.dateTime().toPyDateTime()
interval = self.increment_interval.value()

for file in self.files:
    self.set_file_time(file, current_time)
    current_time += timedelta(seconds=interval)

源碼下載

import sys
import os
import platform
from datetime import datetime, timedelta
import pytz
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, 
                            QLabel, QPushButton, QListWidget, QDateTimeEdit, QComboBox, 
                            QRadioButton, QButtonGroup, QGroupBox, QFileDialog, QMessageBox,
                            QSpinBox, QCheckBox, QTabWidget, QStyleFactory)
from PyQt5.QtCore import Qt, QDateTime, QTimer
from PyQt5.QtGui import QIcon, QPalette, QColor

class TimeStampEditor(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("文件時(shí)間戳編輯器")
        self.setGeometry(100, 100, 800, 600)
        
        # 設(shè)置應(yīng)用樣式和配色
        self.setStyle(QStyleFactory.create('Fusion'))
        self.set_dark_theme()
        
        # 初始化UI
        self.init_ui()
        
        # 初始化變量
        self.files = []
        self.system = platform.system()
        
        # 設(shè)置窗口圖標(biāo)
        self.setWindowIcon(QIcon(self.style().standardIcon(getattr(self.style(), 'SP_FileDialogListView'))))

    def set_dark_theme(self):
        """設(shè)置暗色主題"""
        dark_palette = QPalette()
        
        # 基礎(chǔ)顏色
        dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
        dark_palette.setColor(QPalette.WindowText, Qt.white)
        dark_palette.setColor(QPalette.Base, QColor(35, 35, 35))
        dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
        dark_palette.setColor(QPalette.ToolTipBase, QColor(25, 25, 25))
        dark_palette.setColor(QPalette.ToolTipText, Qt.white)
        dark_palette.setColor(QPalette.Text, Qt.white)
        dark_palette.setColor(QPalette.Button, QColor(53, 53, 53))
        dark_palette.setColor(QPalette.ButtonText, Qt.white)
        dark_palette.setColor(QPalette.BrightText, Qt.red)
        dark_palette.setColor(QPalette.Link, QColor(42, 130, 218))
        dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
        dark_palette.setColor(QPalette.HighlightedText, QColor(35, 35, 35))
        
        # 禁用顏色
        dark_palette.setColor(QPalette.Disabled, QPalette.ButtonText, Qt.darkGray)
        dark_palette.setColor(QPalette.Disabled, QPalette.WindowText, Qt.darkGray)
        dark_palette.setColor(QPalette.Disabled, QPalette.Text, Qt.darkGray)
        
        QApplication.setPalette(dark_palette)
        self.setPalette(dark_palette)

    def init_ui(self):
        """初始化用戶界面"""
        main_widget = QWidget()
        main_layout = QVBoxLayout()
        
        # 創(chuàng)建標(biāo)簽頁
        tab_widget = QTabWidget()
        
        # 第一個(gè)標(biāo)簽頁 - 基本設(shè)置
        basic_tab = QWidget()
        basic_layout = QVBoxLayout()
        
        # 文件選擇部分
        file_group = QGroupBox("?? 選擇文件")
        file_layout = QVBoxLayout()
        
        self.file_list = QListWidget()
        self.file_list.setSelectionMode(QListWidget.ExtendedSelection)
        
        btn_layout = QHBoxLayout()
        self.add_file_btn = QPushButton("? 添加文件")
        self.add_file_btn.clicked.connect(self.add_files)
        self.add_folder_btn = QPushButton("?? 添加文件夾")
        self.add_folder_btn.clicked.connect(self.add_folder)
        self.remove_btn = QPushButton("? 移除選中")
        self.remove_btn.clicked.connect(self.remove_files)
        self.clear_btn = QPushButton("?? 清空列表")
        self.clear_btn.clicked.connect(self.clear_files)
        
        btn_layout.addWidget(self.add_file_btn)
        btn_layout.addWidget(self.add_folder_btn)
        btn_layout.addWidget(self.remove_btn)
        btn_layout.addWidget(self.clear_btn)
        
        file_layout.addLayout(btn_layout)
        file_layout.addWidget(self.file_list)
        file_group.setLayout(file_layout)
        
        # 時(shí)間設(shè)置部分
        time_group = QGroupBox("? 時(shí)間設(shè)置")
        time_layout = QVBoxLayout()
        
        # 時(shí)間操作類型
        self.time_op_group = QButtonGroup()
        self.set_time_rb = QRadioButton("設(shè)置為指定時(shí)間")
        self.adjust_time_rb = QRadioButton("調(diào)整時(shí)間 (加減)")
        self.timezone_rb = QRadioButton("時(shí)區(qū)轉(zhuǎn)換")
        
        self.set_time_rb.setChecked(True)
        self.time_op_group.addButton(self.set_time_rb)
        self.time_op_group.addButton(self.adjust_time_rb)
        self.time_op_group.addButton(self.timezone_rb)
        
        # 時(shí)間選擇器
        self.datetime_edit = QDateTimeEdit()
        self.datetime_edit.setDateTime(QDateTime.currentDateTime())
        self.datetime_edit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        self.datetime_edit.setCalendarPopup(True)
        
        # 時(shí)間調(diào)整控件
        adjust_layout = QHBoxLayout()
        self.hours_spin = QSpinBox()
        self.hours_spin.setRange(-24, 24)
        self.minutes_spin = QSpinBox()
        self.minutes_spin.setRange(-60, 60)
        self.seconds_spin = QSpinBox()
        self.seconds_spin.setRange(-60, 60)
        
        adjust_layout.addWidget(QLabel("小時(shí):"))
        adjust_layout.addWidget(self.hours_spin)
        adjust_layout.addWidget(QLabel("分鐘:"))
        adjust_layout.addWidget(self.minutes_spin)
        adjust_layout.addWidget(QLabel("秒:"))
        adjust_layout.addWidget(self.seconds_spin)
        
        # 時(shí)區(qū)選擇
        self.timezone_combo = QComboBox()
        self.timezone_combo.addItems(pytz.all_timezones)
        current_tz = datetime.now().astimezone().tzinfo
        self.timezone_combo.setCurrentText(str(current_tz))
        
        # 堆疊控件
        self.time_stack = QWidget()
        stack_layout = QVBoxLayout()
        stack_layout.addWidget(self.datetime_edit)
        
        adjust_widget = QWidget()
        adjust_widget.setLayout(adjust_layout)
        stack_layout.addWidget(adjust_widget)
        
        stack_layout.addWidget(self.timezone_combo)
        self.time_stack.setLayout(stack_layout)
        
        # 默認(rèn)顯示第一個(gè)控件
        self.datetime_edit.show()
        adjust_widget.hide()
        self.timezone_combo.hide()
        
        # 連接信號
        self.set_time_rb.toggled.connect(lambda: self.switch_time_mode(0))
        self.adjust_time_rb.toggled.connect(lambda: self.switch_time_mode(1))
        self.timezone_rb.toggled.connect(lambda: self.switch_time_mode(2))
        
        # 時(shí)間類型選擇布局
        op_layout = QHBoxLayout()
        op_layout.addWidget(self.set_time_rb)
        op_layout.addWidget(self.adjust_time_rb)
        op_layout.addWidget(self.timezone_rb)
        
        time_layout.addLayout(op_layout)
        time_layout.addWidget(self.time_stack)
        
        # 時(shí)間屬性選擇
        attr_layout = QHBoxLayout()
        self.modified_cb = QCheckBox("修改時(shí)間")
        self.modified_cb.setChecked(True)
        self.access_cb = QCheckBox("訪問時(shí)間")
        self.created_cb = QCheckBox("創(chuàng)建時(shí)間")
        
        attr_layout.addWidget(self.modified_cb)
        attr_layout.addWidget(self.access_cb)
        attr_layout.addWidget(self.created_cb)
        
        time_layout.addLayout(attr_layout)
        time_group.setLayout(time_layout)
        
        # 應(yīng)用按鈕
        self.apply_btn = QPushButton("? 應(yīng)用更改")
        self.apply_btn.clicked.connect(self.apply_changes)
        self.apply_btn.setStyleSheet("background-color: #2a82da; color: white; font-weight: bold;")
        
        # 添加到基本標(biāo)簽頁
        basic_layout.addWidget(file_group)
        basic_layout.addWidget(time_group)
        basic_layout.addWidget(self.apply_btn)
        basic_tab.setLayout(basic_layout)
        
        # 第二個(gè)標(biāo)簽頁 - 批量操作
        batch_tab = QWidget()
        batch_layout = QVBoxLayout()
        
        batch_group = QGroupBox("?? 批量操作")
        batch_inner_layout = QVBoxLayout()
        
        # 批量遞增時(shí)間
        increment_group = QGroupBox("?? 批量遞增時(shí)間")
        increment_layout = QVBoxLayout()
        
        self.increment_start = QDateTimeEdit()
        self.increment_start.setDateTime(QDateTime.currentDateTime())
        self.increment_start.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
        
        self.increment_interval = QSpinBox()
        self.increment_interval.setRange(1, 3600)
        self.increment_interval.setValue(60)
        self.increment_interval.setSuffix(" 秒")
        
        increment_layout.addWidget(QLabel("起始時(shí)間:"))
        increment_layout.addWidget(self.increment_start)
        increment_layout.addWidget(QLabel("時(shí)間間隔:"))
        increment_layout.addWidget(self.increment_interval)
        
        self.increment_btn = QPushButton("?? 應(yīng)用遞增時(shí)間")
        self.increment_btn.clicked.connect(self.apply_incremental)
        self.increment_btn.setStyleSheet("background-color: #2a82da; color: white;")
        
        increment_layout.addWidget(self.increment_btn)
        increment_group.setLayout(increment_layout)
        
        batch_inner_layout.addWidget(increment_group)
        batch_group.setLayout(batch_inner_layout)
        
        batch_layout.addWidget(batch_group)
        batch_tab.setLayout(batch_layout)
        
        # 添加標(biāo)簽頁
        tab_widget.addTab(basic_tab, "??? 基本設(shè)置")
        tab_widget.addTab(batch_tab, "?? 批量操作")
        
        main_layout.addWidget(tab_widget)
        main_widget.setLayout(main_layout)
        self.setCentralWidget(main_widget)
        
        # 狀態(tài)欄
        self.status_bar = self.statusBar()
        self.status_bar.showMessage("就緒 ??")
        
        # 連接信號
        self.file_list.itemSelectionChanged.connect(self.update_status)
        
        # 定時(shí)更新當(dāng)前時(shí)間顯示
        self.time_updater = QTimer(self)
        self.time_updater.timeout.connect(self.update_current_time)
        self.time_updater.start(1000)
    
    def switch_time_mode(self, index):
        """切換時(shí)間操作模式"""
        for i in range(self.time_stack.layout().count()):
            widget = self.time_stack.layout().itemAt(i).widget()
            widget.setVisible(i == index)
    
    def update_current_time(self):
        """更新狀態(tài)欄中的當(dāng)前時(shí)間"""
        current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        self.status_bar.showMessage(f"就緒 ?? | 當(dāng)前時(shí)間: {current_time}", 1000)
    
    def update_status(self):
        """更新狀態(tài)欄顯示選中文件數(shù)量"""
        selected = len(self.file_list.selectedItems())
        total = self.file_list.count()
        self.status_bar.showMessage(f"已選 {selected} 個(gè)文件 | 總計(jì) {total} 個(gè)文件", 3000)
    
    def add_files(self):
        """添加文件到列表"""
        files, _ = QFileDialog.getOpenFileNames(self, "選擇文件", "", "所有文件 (*.*)")
        if files:
            for file in files:
                if file not in self.files:
                    self.files.append(file)
                    self.file_list.addItem(file)
            self.update_status()
    
    def add_folder(self):
        """添加文件夾中的所有文件到列表"""
        folder = QFileDialog.getExistingDirectory(self, "選擇文件夾")
        if folder:
            for root, _, files in os.walk(folder):
                for file in files:
                    file_path = os.path.join(root, file)
                    if file_path not in self.files:
                        self.files.append(file_path)
                        self.file_list.addItem(file_path)
            self.update_status()
    
    def remove_files(self):
        """從列表中移除選中的文件"""
        for item in self.file_list.selectedItems():
            self.files.remove(item.text())
            self.file_list.takeItem(self.file_list.row(item))
        self.update_status()
    
    def clear_files(self):
        """清空文件列表"""
        self.files.clear()
        self.file_list.clear()
        self.update_status()
    
    def apply_changes(self):
        """應(yīng)用時(shí)間戳更改"""
        if not self.files:
            QMessageBox.warning(self, "警告", "請先添加文件! ??")
            return
        
        if not (self.modified_cb.isChecked() or self.access_cb.isChecked() or self.created_cb.isChecked()):
            QMessageBox.warning(self, "警告", "請至少選擇一個(gè)時(shí)間屬性! ??")
            return
        
        try:
            if self.set_time_rb.isChecked():
                # 設(shè)置為指定時(shí)間
                new_time = self.datetime_edit.dateTime().toPyDateTime()
                self.set_custom_time(new_time)
            
            elif self.adjust_time_rb.isChecked():
                # 調(diào)整時(shí)間
                delta = timedelta(
                    hours=self.hours_spin.value(),
                    minutes=self.minutes_spin.value(),
                    seconds=self.seconds_spin.value()
                )
                self.adjust_time(delta)
            
            elif self.timezone_rb.isChecked():
                # 時(shí)區(qū)轉(zhuǎn)換
                tz = pytz.timezone(self.timezone_combo.currentText())
                self.convert_timezone(tz)
            
            QMessageBox.information(self, "成功", "時(shí)間戳修改成功! ?")
        
        except Exception as e:
            QMessageBox.critical(self, "錯(cuò)誤", f"修改時(shí)間戳?xí)r出錯(cuò): {str(e)} ?")
    
    def apply_incremental(self):
        """應(yīng)用遞增時(shí)間"""
        if not self.files:
            QMessageBox.warning(self, "警告", "請先添加文件! ??")
            return
        
        if not (self.modified_cb.isChecked() or self.access_cb.isChecked() or self.created_cb.isChecked()):
            QMessageBox.warning(self, "警告", "請至少選擇一個(gè)時(shí)間屬性! ??")
            return
        
        try:
            current_time = self.increment_start.dateTime().toPyDateTime()
            interval = self.increment_interval.value()
            
            for file in self.files:
                if os.path.exists(file):
                    self.set_file_time(file, current_time)
                    current_time += timedelta(seconds=interval)
            
            QMessageBox.information(self, "成功", "批量遞增時(shí)間應(yīng)用成功! ?")
        
        except Exception as e:
            QMessageBox.critical(self, "錯(cuò)誤", f"應(yīng)用遞增時(shí)間時(shí)出錯(cuò): {str(e)} ?")
    
    def set_custom_time(self, new_time):
        """設(shè)置自定義時(shí)間"""
        for file in self.files:
            if os.path.exists(file):
                self.set_file_time(file, new_time)
    
    def adjust_time(self, delta):
        """調(diào)整時(shí)間"""
        for file in self.files:
            if os.path.exists(file):
                # 獲取當(dāng)前時(shí)間戳
                stat = os.stat(file)
                atime = datetime.fromtimestamp(stat.st_atime)
                mtime = datetime.fromtimestamp(stat.st_mtime)
                
                # 如果是Windows系統(tǒng),可以獲取創(chuàng)建時(shí)間
                if self.system == 'Windows':
                    ctime = datetime.fromtimestamp(stat.st_ctime)
                else:
                    ctime = datetime.fromtimestamp(stat.st_mtime)
                
                # 應(yīng)用調(diào)整
                new_atime = atime + delta if self.access_cb.isChecked() else atime
                new_mtime = mtime + delta if self.modified_cb.isChecked() else mtime
                new_ctime = ctime + delta if self.created_cb.isChecked() else ctime
                
                # 設(shè)置新時(shí)間
                self.set_file_time(file, new_atime, new_mtime, new_ctime)
    
    def convert_timezone(self, target_tz):
        """轉(zhuǎn)換時(shí)區(qū)"""
        for file in self.files:
            if os.path.exists(file):
                # 獲取當(dāng)前時(shí)間戳
                stat = os.stat(file)
                atime = datetime.fromtimestamp(stat.st_atime)
                mtime = datetime.fromtimestamp(stat.st_mtime)
                
                # 如果是Windows系統(tǒng),可以獲取創(chuàng)建時(shí)間
                if self.system == 'Windows':
                    ctime = datetime.fromtimestamp(stat.st_ctime)
                else:
                    ctime = datetime.fromtimestamp(stat.st_mtime)
                
                # 假設(shè)原始時(shí)間是本地時(shí)區(qū),轉(zhuǎn)換為目標(biāo)時(shí)區(qū)
                local_tz = pytz.timezone('UTC')
                if hasattr(datetime, 'astimezone'):
                    # Python 3.3+
                    atime = atime.astimezone(target_tz)
                    mtime = mtime.astimezone(target_tz)
                    ctime = ctime.astimezone(target_tz)
                else:
                    # 舊版Python
                    atime = local_tz.localize(atime).astimezone(target_tz)
                    mtime = local_tz.localize(mtime).astimezone(target_tz)
                    ctime = local_tz.localize(ctime).astimezone(target_tz)
                
                # 轉(zhuǎn)換為naive datetime
                atime = atime.replace(tzinfo=None)
                mtime = mtime.replace(tzinfo=None)
                ctime = ctime.replace(tzinfo=None)
                
                # 設(shè)置新時(shí)間
                new_atime = atime if self.access_cb.isChecked() else datetime.fromtimestamp(stat.st_atime)
                new_mtime = mtime if self.modified_cb.isChecked() else datetime.fromtimestamp(stat.st_mtime)
                new_ctime = ctime if self.created_cb.isChecked() else datetime.fromtimestamp(stat.st_ctime if self.system == 'Windows' else stat.st_mtime)
                
                self.set_file_time(file, new_atime, new_mtime, new_ctime)
    
    def set_file_time(self, file_path, atime=None, mtime=None, ctime=None):
        """設(shè)置文件時(shí)間戳"""
        if atime is None and mtime is None and ctime is None:
            return
        
        # 如果只提供了一個(gè)時(shí)間,則所有選中的時(shí)間屬性都使用該時(shí)間
        if mtime is None and ctime is None:
            mtime = atime if self.modified_cb.isChecked() else None
            atime = atime if self.access_cb.isChecked() else None
            ctime = atime if self.created_cb.isChecked() else None
        
        # 轉(zhuǎn)換為時(shí)間戳
        atime_ts = atime.timestamp() if atime is not None else None
        mtime_ts = mtime.timestamp() if mtime is not None else None
        
        # 設(shè)置訪問和修改時(shí)間
        if atime_ts is not None or mtime_ts is not None:
            os.utime(file_path, (atime_ts or os.stat(file_path).st_atime, 
                                mtime_ts or os.stat(file_path).st_mtime))
        
        # 設(shè)置創(chuàng)建時(shí)間 (Windows only)
        if self.system == 'Windows' and ctime is not None and self.created_cb.isChecked():
            try:
                import win32file
                import win32con
                import pywintypes
                
                # 轉(zhuǎn)換為Windows文件時(shí)間格式
                wintime = pywintypes.Time(ctime)
                
                # 打開文件句柄
                handle = win32file.CreateFile(
                    file_path, win32con.GENERIC_WRITE,
                    win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE | win32con.FILE_SHARE_DELETE,
                    None, win32con.OPEN_EXISTING,
                    win32con.FILE_ATTRIBUTE_NORMAL, None)
                
                # 設(shè)置創(chuàng)建時(shí)間
                win32file.SetFileTime(handle, wintime, None, None)
                
                # 關(guān)閉句柄
                handle.Close()
            except ImportError:
                QMessageBox.warning(self, "警告", "需要pywin32庫來修改創(chuàng)建時(shí)間 (僅Windows)")
            except Exception as e:
                QMessageBox.warning(self, "警告", f"修改創(chuàng)建時(shí)間時(shí)出錯(cuò): {str(e)}")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setStyle('Fusion')
    
    # 設(shè)置應(yīng)用信息
    app.setApplicationName("文件時(shí)間戳編輯器")
    app.setApplicationDisplayName("文件時(shí)間戳編輯器")
    
    window = TimeStampEditor()
    window.show()
    sys.exit(app.exec_())

總結(jié)與擴(kuò)展

開發(fā)經(jīng)驗(yàn)總結(jié)

跨平臺兼容性處理是核心難點(diǎn)

PyQt5的信號槽機(jī)制大幅簡化了UI交互開發(fā)

合理的狀態(tài)管理對用戶體驗(yàn)至關(guān)重要

擴(kuò)展方向

  • 添加時(shí)間戳預(yù)設(shè)模板
  • 集成文件內(nèi)容修改時(shí)間識別
  • 支持正則表達(dá)式篩選文件
  • 開發(fā)插件系統(tǒng)

以上就是Python+PyQt5開發(fā)超全能的文件時(shí)間戳修改器的詳細(xì)內(nèi)容,更多關(guān)于Python文件時(shí)間戳修改的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python中函數(shù)總結(jié)之裝飾器閉包詳解

    python中函數(shù)總結(jié)之裝飾器閉包詳解

    下面小編就為大家?guī)硪黄猵ython中函數(shù)總結(jié)之裝飾器閉包詳解。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-06-06
  • Python連接Postgres/Mysql/Mongo數(shù)據(jù)庫基本操作大全

    Python連接Postgres/Mysql/Mongo數(shù)據(jù)庫基本操作大全

    在后端應(yīng)用開發(fā)中,經(jīng)常會用到Postgres/Mysql/Mongo這三種數(shù)據(jù)庫的基本操作,今天小編就給大家詳細(xì)介紹Python連接Postgres/Mysql/Mongo數(shù)據(jù)庫基本操作,感興趣的朋友一起看看吧
    2021-06-06
  • Python 結(jié)巴分詞實(shí)現(xiàn)關(guān)鍵詞抽取分析

    Python 結(jié)巴分詞實(shí)現(xiàn)關(guān)鍵詞抽取分析

    這篇文章主要介紹了Python 結(jié)巴分詞實(shí)現(xiàn)關(guān)鍵詞抽取分析,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-10-10
  • TensorFlow人工智能學(xué)習(xí)Keras高層接口應(yīng)用示例

    TensorFlow人工智能學(xué)習(xí)Keras高層接口應(yīng)用示例

    這篇文章主要為大家介紹了TensorFlow人工智能學(xué)習(xí)中Keras高層接口的應(yīng)用示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2021-11-11
  • Python中常見內(nèi)置函數(shù)的用法合集

    Python中常見內(nèi)置函數(shù)的用法合集

    本文將從基礎(chǔ)到高級,詳細(xì)介紹Python中常見的內(nèi)置函數(shù),通過代碼示例和中文注釋,幫助您深入理解如何在不同情景下靈活應(yīng)用這些函數(shù),需要的可以學(xué)習(xí)一下
    2023-09-09
  • Python 翻譯詞典小程序功能說明

    Python 翻譯詞典小程序功能說明

    本工具是基于Python開發(fā)的智能翻譯系統(tǒng),采用有道詞典進(jìn)行翻譯,并具有本地詞典緩存以及單詞本功能,這篇文章主要介紹了Python 翻譯詞典小程序,需要的朋友可以參考下
    2025-05-05
  • Python pandas實(shí)現(xiàn)excel工作表合并功能詳解

    Python pandas實(shí)現(xiàn)excel工作表合并功能詳解

    這篇文章主要介紹了Python pandas實(shí)現(xiàn)excel工作表合并功能以及相關(guān)實(shí)例代碼,需要的朋友們參考學(xué)習(xí)下。
    2019-08-08
  • OpenCV角點(diǎn)檢測的實(shí)現(xiàn)示例

    OpenCV角點(diǎn)檢測的實(shí)現(xiàn)示例

    角點(diǎn)通常被定義為兩條邊的交點(diǎn),本文主要介紹了OpenCV角點(diǎn)檢測的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 詳解python字節(jié)碼

    詳解python字節(jié)碼

    本篇文章給大家總結(jié)了關(guān)于python字節(jié)碼的相關(guān)知識點(diǎn)以及知識點(diǎn)分析,對此有需要的朋友參考學(xué)習(xí)下。
    2018-02-02
  • Python?全局空間和局部空間

    Python?全局空間和局部空間

    這篇文章主要介紹了Python?全局空間和局部空間,命名空間的概念的提出是為了劃分和控制變量是否可見,以及生存周期的長短;命名空間的作用范圍叫做作用域更多詳細(xì)內(nèi)容需要的小伙伴可以參考一下
    2022-04-04

最新評論