{"id":2087,"date":"2022-01-01T15:16:54","date_gmt":"2022-01-01T07:16:54","guid":{"rendered":"https:\/\/guerilla.ddns.net\/wp\/?p=2087"},"modified":"2025-08-22T22:35:11","modified_gmt":"2025-08-22T14:35:11","slug":"how-can-i-check-file-size-in-python","status":"publish","type":"post","link":"https:\/\/guerilla.ddns.net\/wp\/?p=2087","title":{"rendered":"How can I check file size in Python?"},"content":{"rendered":"<pre><code class=\"language-python\" data-line=\"\">import os\nos.path.getsize(&#039;C:\\\\Python27\\\\Lib\\\\genericpath.py&#039;)<\/code><\/pre>\n<p>or<\/p>\n<pre><code class=\"language-python\" data-line=\"\">import os\nos.stat(&#039;C:\\\\Python27\\\\Lib\\\\genericpath.py&#039;).st_size<\/code><\/pre>\n<p>or<\/p>\n<pre><code class=\"language-python\" data-line=\"\">from pathlib import Path\nPath(&#039;C:\\\\Python27\\\\Lib\\\\genericpath.py&#039;).stat().st_size<\/code><\/pre>\n<p>&nbsp;<br \/>\nBy the way, to convert from bytes to any other unit by doing a right shift by 10 you basically shift it by an order (multiple).<br \/>\n&nbsp;<br \/>\nExample: 5GB are 5368709120 bytes<\/p>\n<pre>print (5368709120 >> 10)  # 5242880 kilobytes (kB)\r\nprint (5368709120 >> 20 ) # 5120 megabytes (MB)\r\nprint (5368709120 >> 30 ) # 5 gigabytes (GB)<\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<br \/>\nref:<br \/>\n\u2022 <a href=\"https:\/\/stackoverflow.com\/questions\/6591931\/getting-file-size-in-python\" rel=\"noopener\" target=\"_blank\"><em>Getting file size in Python?<\/em><\/a><br \/>\n\u2022 <a href=\"https:\/\/stackoverflow.com\/questions\/2104080\/how-can-i-check-file-size-in-python\" rel=\"noopener\" target=\"_blank\"><em>How can I check file size in Python?<\/em><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import os os.path.getsize(&#039;C:\\\\Python27\\\\Lib\\\\gene [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[212],"tags":[27,187],"class_list":["post-2087","post","type-post","status-publish","format-standard","hentry","category-coding","tag-coding","tag-python"],"_links":{"self":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2087"}],"version-history":[{"count":8,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2087\/revisions"}],"predecessor-version":[{"id":3394,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2087\/revisions\/3394"}],"wp:attachment":[{"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2087"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guerilla.ddns.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}