「Python」getsize()メソッドでファイルのサイズを取得するサンプル

書式
os.path.getsize(path)
path のサイズをバイト数で返します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import os
targetPath = "C:\\study\\pleiades-2020-12-java-win-64bit-jre_20201222.zip"
fileSize = os.path.getsize(targetPath)
print("ファイルのサイズのバイト数")
print (fileSize)
# coding: utf-8 import os targetPath = "C:\\study\\pleiades-2020-12-java-win-64bit-jre_20201222.zip" fileSize = os.path.getsize(targetPath) print("ファイルのサイズのバイト数") print (fileSize)
# coding: utf-8
import os

targetPath = "C:\\study\\pleiades-2020-12-java-win-64bit-jre_20201222.zip"

fileSize = os.path.getsize(targetPath)
print("ファイルのサイズのバイト数")
print (fileSize)

実行結果
>python test.py
ファイルのサイズのバイト数
1854136107

Python

Posted by arkgame