{"id":23673,"date":"2022-08-05T18:06:24","date_gmt":"2022-08-05T12:36:24","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=23673"},"modified":"2022-08-05T18:06:28","modified_gmt":"2022-08-05T12:36:28","slug":"python-get-file-size","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-get-file-size\/","title":{"rendered":"4 Methods to Get Python File Size Easily"},"content":{"rendered":"\n<p>In this article, we will cover information about our talking point in python &#8211; get file size. Knowing the size of any file in python programming is crucial because it determines if you can use the following file in your program. Certain programs can support only a particular file type and size; therefore, file handling is vital, and knowing file size is a significant part of file handling.<\/p>\n\n\n\n<p>There exist many ways in python to get file size. We will discuss four methods in this article, three of the methods use the os module in python, and one uses the &#8216;pathlib&#8217; module. Os module in python enables interaction with the operating system of the computer. Besides, the os module &#8216;pathlib&#8217; library eases the process the deal with file paths. To know more about the os module, check out python&#8217;s official <a href=\"https:\/\/docs.python.org\/3\/library\/os.html?highlight=os%20module#module-os\" target=\"_blank\" rel=\"noreferrer noopener\">documentation<\/a>.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Python_Get_File_Size_Method_1\" >Python Get File Size Method 1<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_1\" >Example 1<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Python_Get_File_Size_Method_2\" >Python Get File Size Method 2<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_2\" >Example 2<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Python_Get_File_Size_Method_3\" >Python Get File Size Method 3<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_3\" >Example 3<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Python_Get_File_Size_Method_4\" >Python Get File Size Method 4<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_4\" >Example 4<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Python_Get_File_Size_In_KB_MB_GB\" >Python Get File Size In KB, MB &amp; GB.<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_5\" >Example 5<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Python_Get_File_Creation_and_Modification_Date\" >Python Get File Creation and Modification Date<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_6\" >Example 6<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Get_File_Size_From_Url\" >Get File Size From Url<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Example_7\" >Example 7<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#FAQs_on_Python_get_file_size\" >FAQs on Python get file size<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#Trending_Python_Articles\" >Trending Python Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-python-get-file-size-method-1\"><span class=\"ez-toc-section\" id=\"Python_Get_File_Size_Method_1\"><\/span>Python Get File Size Method 1<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/07\/python-get-file-size.png\" alt=\"Methods to Get Python File Size Easily\" class=\"wp-image-23727\" width=\"547\" height=\"410\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/07\/python-get-file-size.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/07\/python-get-file-size-300x225.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/07\/python-get-file-size-768x576.png 768w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure>\n\n\n\n<p>Firstly we will discuss three methods that use the os module but are different in usage and also have different syntaxes. <strong>Method one is &#8216;os.stat()&#8217; function<\/strong>. This function needs a file path as an argument and, in return, provides statistical data about the file. It can also be used to get file size.  <\/p>\n\n\n\n<p>To use &#8216;os.stat(),&#8217; you need to follow the steps given below:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import the os module into your code.<\/li><li>Then use the syntax os.stat( &#8216;insert your file path here&#8217; ).<\/li><li>Print the results.<\/li><\/ol>\n\n\n\n<p>Let&#8217;s understand better with the help of an example<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-1\"><span class=\"ez-toc-section\" id=\"Example_1\"><\/span>Example 1<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport os\n\nsize = os.stat(r'C:\\mydata\\testdata1.txt')\nprint(&quot;File size:&quot;, size,&quot;bytes&quot;)\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nFile size: 204318 bytes\n<\/pre><\/div>\n\n\n<p>As you can see, this function determines file size in terms of bytes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-get-file-size-method-2\"><span class=\"ez-toc-section\" id=\"Python_Get_File_Size_Method_2\"><\/span>Python Get File Size Method 2<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>In method 2, we will use &#8216;os.path.getsize()&#8217; function<\/strong>, which similarly takes the file path as an argument and, in return, provides file size in bytes.<\/p>\n\n\n\n<p>Follow the steps given below to use this function:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import os module in your code.<\/li><li>Use the syntax os.path.getsize( &#8216;insert your file path here&#8217; ).<\/li><li>Print the results.<\/li><\/ol>\n\n\n\n<p>Let&#8217;s understand better with the help of an example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-2\"><span class=\"ez-toc-section\" id=\"Example_2\"><\/span>Example 2<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport os\n \nsize = os.path.getsize(r'C:\\mydata\\testdata2.txt')\nprint(&quot;File size:&quot;, size, &quot;bytes&quot;)\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nFile size: 102284 bytes\n<\/pre><\/div>\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-juliett monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-image\"><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/a><\/div><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-get-file-size-method-3\"><span class=\"ez-toc-section\" id=\"Python_Get_File_Size_Method_3\"><\/span>Python Get File Size Method 3 <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In addition to methods 1 &amp; 2, method 3 also uses the os module. Although we use different functions to get file size,<strong> &#8216;open()&#8217; function to open a file and &#8216;seek()&#8217; function to get file size.<\/strong><\/p>\n\n\n\n<p>Follow the steps given below to get file size:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import os module.<\/li><li>Open the file using &#8216;open()&#8217; function.<\/li><li>Get file size using &#8216;seek()&#8217; function.<\/li><li>Print the results.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-3\"><span class=\"ez-toc-section\" id=\"Example_3\"><\/span>Example 3<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport os\nwith  open(r'C:\\mydata\\testdata2.txt') as size:\n    size.seek(0, os.SEEK_END)\n    print('File size:', size.tell(), 'bytes')\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nFile size: 102284 bytes\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-get-file-size-method-4\"><span class=\"ez-toc-section\" id=\"Python_Get_File_Size_Method_4\"><\/span>Python Get File Size Method 4 <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>In method 4, we will use the &#8216;pathlib&#8217; module<\/strong>. &#8216;pathlib&#8217; module offers classes representing filesystem paths along with semantics which is appropriate for different computer operating systems. Moreover &#8216;patlib&#8217; module offers inbuilt functions which are capable of providing file size.<\/p>\n\n\n\n<p>Further, to get the file size, follow the steps given below:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import &#8216;pathlib&#8217; in your code in addition to that from path &#8216;parthlib&#8217; module import Path. Although this can be done in one line of code.<\/li><li>Use .stat() to open the file<\/li><li>Further, use .st_size as shown below in the example code to get the file size.<\/li><li>Print the results. <\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-4\"><span class=\"ez-toc-section\" id=\"Example_4\"><\/span>Example 4<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom pathlib import Path\n\nPath(r'C:\\mydata\\testdata1.txt').stat()\nsize =Path(r'C:\\mydata\\testdata4.txt').stat().st_size\nprint(&quot;File size:&quot;, size, &quot;bytes&quot;)\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nFile size: 331560 bytes\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-get-file-size-in-kb-mb-gb\"><span class=\"ez-toc-section\" id=\"Python_Get_File_Size_In_KB_MB_GB\"><\/span>Python Get File Size In KB, MB &amp; GB.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>All the methods we covered above provide us data in bytes nevertheless, you might want file size in KB, MB, or GB. Thus to do so, you can use the example given below to convert your files to your desired size.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-5\"><span class=\"ez-toc-section\" id=\"Example_5\"><\/span>Example 5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport os.path\n\npath = r'C:\\mydata\\testdata2.txt'\nsize = os.path.getsize(path)\n\nprint('File size in Bytes: ' + str(size))\nprint('File size in KB: ' + str(size\/1024))\nprint('File size in MB: ' + str(size\/1024**2))\nprint('File size in GB: ' + str(size\/1024**3))\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nFile size in Bytes: 331560\nFile size in KB: 323.78906\nFile size in MB: 0.3162\nFile size in GB: 0.00031\n<\/pre><\/div>\n\n\n<p>In the above example we have used &#8216;os.path.getsize()&#8217; function. Although you can use your preferred function to get the file size and then use the syntax given in the example to convert it to various sizes. <\/p>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-golf monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\">[Fixed] nameerror: name Unicode is not defined<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-get-file-creation-and-modification-date\"><span class=\"ez-toc-section\" id=\"Python_Get_File_Creation_and_Modification_Date\"><\/span>Python Get File Creation and Modification Date<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes you might want to see when the file was created or when it was last modified. To do that, you need to follow the steps given below:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import os.path module.<\/li><li>From os.path import datetime.<\/li><li>Use syntax time.ctime(os.path.getmtime(r&#8217;your file path&#8217;)) to get modification date.<\/li><li>Use syntax time.ctime(os.path.getctime(r&#8217;your file path&#8217;)) to get last creation date.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-6\"><span class=\"ez-toc-section\" id=\"Example_6\"><\/span>Example 6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom os.path import datetime\nprint(time.ctime(os.path.getmtime(r'C:\\mydata\\testdata1.txt')))\nprint(time.ctime(os.path.getctime(r'your file path')))\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nFri Jul 29 19:45:23 2022\nFri Jul 29 19:45:23 2022\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-get-file-size-from-url\"><span class=\"ez-toc-section\" id=\"Get_File_Size_From_Url\"><\/span>Get File Size From Url<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you want to get file size from url of a file, you can use the <a href=\"http:\/\/www.pythonpool.com\/urllib-error-httperror-http-error-403-forbidden\/\" target=\"_blank\" rel=\"noopener\">urllib<\/a> package and follow the given steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Import urllib package.<\/li><li>Define a variable containing the url.<\/li><li>use &#8216;length()&#8217; function to get file size.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-example-7\"><span class=\"ez-toc-section\" id=\"Example_7\"><\/span>Example 7<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport urllib.request\nfile=urllib.request.urlopen(&quot;https:\/\/sample-videos.com\/xls\/Sample-Spreadsheet-10-rows.xls&quot;)\nprint(&quot;File size:&quot;, file.length, &quot;bytes&quot;)\n<\/pre><\/div>\n\n\n<p class=\"has-base-2-background-color has-background\">Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nFile size: 16102 bytes\n<\/pre><\/div>\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-alpha monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\">[Solved] runtimeerror: cuda error: invalid device ordinal<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs-on-python-get-file-size\"><span class=\"ez-toc-section\" id=\"FAQs_on_Python_get_file_size\"><\/span>FAQs on Python get file size<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1659333751249\"><strong class=\"schema-faq-question\">How do you get the file size of all files in a directory?<\/strong> <p class=\"schema-faq-answer\">You can use the &#8216;scandir()&#8217; function to get the file size of the directory.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1659333878718\"><strong class=\"schema-faq-question\">How to get the file size of the CSV file?<\/strong> <p class=\"schema-faq-answer\">All the methods mentioned in this article can be used to get the size of the CSV file.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1659333984765\"><strong class=\"schema-faq-question\">How to get python file content length?<\/strong> <p class=\"schema-faq-answer\">You can get python file content length using the methods discussed in this article.<\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we saw how different functions can be used to get the file size and how they are different in terms of technicality and usage. One may use these functions however their code allows them to. To know more about files and understand their work with python, check this <a href=\"http:\/\/www.pythonpool.com\/python-check-if-file-exists\/\" target=\"_blank\" rel=\"noreferrer noopener\">post<\/a>.<\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-delta monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-2\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Python_Articles\"><\/span>Trending Python Articles<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 11, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined.webp 1200w \" alt=\"[Fixed] nameerror: name Unicode is not defined\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal.webp 1200w \" alt=\"[Solved] runtimeerror: cuda error: invalid device ordinal\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method.webp 1200w \" alt=\"[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>In this article, we will cover information about our talking point in python &#8211; get file size. Knowing the size of any file in python &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"4 Methods to Get Python File Size Easily\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/#more-23673\" aria-label=\"More on 4 Methods to Get Python File Size Easily\">Read more<\/a><\/p>\n","protected":false},"author":32,"featured_media":23797,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[5351,5345,5347,5348,5349,5344,5346,5350],"class_list":["post-23673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-python-file-size-and-date","tag-python-get-file-size-and-date","tag-python-get-file-size-from-file-object","tag-python-get-file-size-from-url","tag-python-get-file-size-in-directory","tag-python-get-file-size-in-mb","tag-python-get-file-size-on-disk","tag-python-get-files-and-size","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>4 Methods to Get Python File Size Easily - Python Pool<\/title>\n<meta name=\"description\" content=\"Python get file size various methods and their usage. Methods: os.stat(), os.path.getsize(), using pathlib module.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-get-file-size\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"4 Methods to Get Python File Size Easily\" \/>\n<meta property=\"og:description\" content=\"In this article, we will cover information about our talking point in python - get file size. Knowing the size of any file in python programming is\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-get-file-size\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-05T12:36:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-05T12:36:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Yugmil Patel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yugmil Patel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/\"},\"author\":{\"name\":\"Yugmil Patel\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/93f03f9a968d1187cbce46a3586cdac5\"},\"headline\":\"4 Methods to Get Python File Size Easily\",\"datePublished\":\"2022-08-05T12:36:24+00:00\",\"dateModified\":\"2022-08-05T12:36:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/\"},\"wordCount\":865,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp\",\"keywords\":[\"python file size and date\",\"python get file size and date\",\"python get file size from file object\",\"python get file size from url\",\"python get file size in directory\",\"python get file size in mb\",\"python get file size on disk\",\"python get files and size\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-get-file-size\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/\",\"name\":\"4 Methods to Get Python File Size Easily - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp\",\"datePublished\":\"2022-08-05T12:36:24+00:00\",\"dateModified\":\"2022-08-05T12:36:28+00:00\",\"description\":\"Python get file size various methods and their usage. Methods: os.stat(), os.path.getsize(), using pathlib module.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333751249\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333878718\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333984765\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-get-file-size\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp\",\"width\":1200,\"height\":628,\"caption\":\"Python get file size\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"4 Methods to Get Python File Size Easily\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/93f03f9a968d1187cbce46a3586cdac5\",\"name\":\"Yugmil Patel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2d861c3b6baf176f665bbbb1201d50ca0c6a8a7ee922b55157086205707c341d?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2d861c3b6baf176f665bbbb1201d50ca0c6a8a7ee922b55157086205707c341d?s=96&d=wavatar&r=g\",\"caption\":\"Yugmil Patel\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333751249\",\"position\":1,\"url\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333751249\",\"name\":\"How do you get the file size of all files in a directory?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"You can use the 'scandir()' function to get the file size of the directory.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333878718\",\"position\":2,\"url\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333878718\",\"name\":\"How to get the file size of the CSV file?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"All the methods mentioned in this article can be used to get the size of the CSV file.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333984765\",\"position\":3,\"url\":\"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333984765\",\"name\":\"How to get python file content length?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"You can get python file content length using the methods discussed in this article.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"4 Methods to Get Python File Size Easily - Python Pool","description":"Python get file size various methods and their usage. Methods: os.stat(), os.path.getsize(), using pathlib module.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python-get-file-size\/","og_locale":"en_US","og_type":"article","og_title":"4 Methods to Get Python File Size Easily","og_description":"In this article, we will cover information about our talking point in python - get file size. Knowing the size of any file in python programming is","og_url":"https:\/\/www.pythonpool.com\/python-get-file-size\/","og_site_name":"Python Pool","article_published_time":"2022-08-05T12:36:24+00:00","article_modified_time":"2022-08-05T12:36:28+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp","type":"image\/webp"}],"author":"Yugmil Patel","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Yugmil Patel","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/"},"author":{"name":"Yugmil Patel","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/93f03f9a968d1187cbce46a3586cdac5"},"headline":"4 Methods to Get Python File Size Easily","datePublished":"2022-08-05T12:36:24+00:00","dateModified":"2022-08-05T12:36:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/"},"wordCount":865,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp","keywords":["python file size and date","python get file size and date","python get file size from file object","python get file size from url","python get file size in directory","python get file size in mb","python get file size on disk","python get files and size"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-get-file-size\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/","url":"https:\/\/www.pythonpool.com\/python-get-file-size\/","name":"4 Methods to Get Python File Size Easily - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp","datePublished":"2022-08-05T12:36:24+00:00","dateModified":"2022-08-05T12:36:28+00:00","description":"Python get file size various methods and their usage. Methods: os.stat(), os.path.getsize(), using pathlib module.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333751249"},{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333878718"},{"@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333984765"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-get-file-size\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/08\/Python-get-file-size.webp","width":1200,"height":628,"caption":"Python get file size"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"4 Methods to Get Python File Size Easily"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/93f03f9a968d1187cbce46a3586cdac5","name":"Yugmil Patel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2d861c3b6baf176f665bbbb1201d50ca0c6a8a7ee922b55157086205707c341d?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d861c3b6baf176f665bbbb1201d50ca0c6a8a7ee922b55157086205707c341d?s=96&d=wavatar&r=g","caption":"Yugmil Patel"}},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333751249","position":1,"url":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333751249","name":"How do you get the file size of all files in a directory?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You can use the 'scandir()' function to get the file size of the directory.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333878718","position":2,"url":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333878718","name":"How to get the file size of the CSV file?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"All the methods mentioned in this article can be used to get the size of the CSV file.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333984765","position":3,"url":"https:\/\/www.pythonpool.com\/python-get-file-size\/#faq-question-1659333984765","name":"How to get python file content length?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You can get python file content length using the methods discussed in this article.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/23673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=23673"}],"version-history":[{"count":14,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/23673\/revisions"}],"predecessor-version":[{"id":24382,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/23673\/revisions\/24382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/23797"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=23673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=23673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=23673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}