Advertisement
Python253

get_file_size

Mar 3rd, 2024 (edited)
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: get_file_size.py
  4. # Author: Jeoi Reqi
  5.  
  6. """
  7. Get File Size Script (In Bytes)
  8.  
  9. This script retrieves the size of a file named 'texty.txt' in the same directory
  10. as the script. It utilizes a function, get_file_size, to get the file size.
  11.  
  12. Requirements:
  13. - Python 3
  14.  
  15. Usage:
  16. 1. Save the script in the same directory as the 'texty.txt' file.
  17. 2. Run the script.
  18. 3. The script will display the size of the 'texty.txt' file in bytes.
  19. """
  20.  
  21. import os
  22.  
  23. def get_file_size(file):
  24.     """Get file size.
  25.  
  26.    Args:
  27.        file (str): Input file.
  28.  
  29.    Returns:
  30.        int: Size of the file in bytes.
  31.  
  32.    """
  33.     return os.stat(file).st_size
  34.  
  35. def main():
  36.     # Specify the file path
  37.     file_path = 'texty.txt'  # Replace 'texty.txt' with the actual file name if needed
  38.  
  39.     # Get file size
  40.     size = get_file_size(file_path)
  41.  
  42.     # Display the result
  43.     print(f"Size of the '{file_path}' file: {size} bytes")
  44.  
  45. if __name__ == "__main__":
  46.     main()
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement