Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5843621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:10:47+00:00 2026-05-22T12:10:47+00:00

I am doing backups in python script but i need to get the size

  • 0

I am doing backups in python script but i need to get the size of tar.gz file created in MB

How can i get the size in MB of that file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:10:47+00:00Added an answer on May 22, 2026 at 12:10 pm

    It’s not clear from your question whether you want to the compressed or uncompressed size of the file, but in the former case, it’s easy with the os.path.getsize function from the os module

    >>> import os
    >>> os.path.getsize('flickrapi-1.2.tar.gz')
    35382L
    

    To get the answer in megabytes you can shift the answer right by 20, e.g.

    os.path.getsize('large.tar.gz') >> 20
    

    Although that operation will be done in integers – if you want to preserve fractions of a megabyte, divide by (1024*1024.0) instead. (Note the .0 so that the divisor will be a float.)

    Update: In the comments below, Johnsyweb points out a useful recipe for more generally producing human readable representations of file sizes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am doing sql server backups like this in script: BACKUP DATABASE databasename TO
I have this script that is doing a scp onto 4 servers and getting
Have made backup script that does well: makes backup zip-file and then uploads it
In Mysql Administrator, when doing backups, what exactly is Compatibility Mode? I'm trying to
I'm doing a webapp and need a backup plan. Here's what I've got so
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Exchange 2010 does not support the ESE API for doing backups like it did
How can I do daily backups for my VisualSVN Repos? Its on a Windows
I am creating a bash script to backup my files with rsync. Backups all
I have looked through a number of tutorials, but I still can't figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.