[英]Python: How can I obtain the filesize of a selected file in PyQt5?
在PyQt5中,可以使用QFileDialog選擇文件。 我知道如何獲取文件名,但是如何獲取文件大小?
不打開文件:
filename, _ = QFileDialog.getOpenFileName(None, 'Open file')
if filename != "":
info = QFileInfo(filename)
size = info.size()
print(info)
打開文件:
filename, _ = QFileDialog.getOpenFileName(None, 'Open file')
if filename != "":
file = QFile(filename)
if file.open(QFile.ReadOnly):
print(file.size())
從文檔中 :
文件對話框有兩種查看模式...詳細信息還顯示文件和目錄名稱的列表,但是在每個名稱旁邊提供其他信息,例如文件大小和修改日期。 使用setViewMode()設置模式:
dialog.setViewMode(QFileDialog::Detail);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.