Skip to content

Shi-web/filedirecsize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Directory Space Calculator

This Python script calculates the total size of all files within a specified directory (including its subdirectories). It's a simple tool that recursively traverses a directory and sums up the sizes of all contained files.

Table of Contents

Requirements

  • Python 3.8.10 or higher
  • Ubuntu 20.04.3 (The script should also work on other Linux distributions and macOS, as well as on Windows with slight modifications.)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/dirspace-calculator.git
  2. Navigate to the project directory:

    cd dirspace-calculator
  3. Ensure Python is installed:

    • You can check your Python version by running:
      python3 --version

Usage

To calculate the total size of all files in the current directory:

  1. Run the script using Python:

    python3 dir_space_calculator.py
  2. The script will output the total size of all files in the directory.

Custom Directory

If you want to calculate the size of a specific directory, modify the main() function in the script:

def main():
    total = dirSpace("/path/to/your/directory")
    print(f"Total size: {total} bytes")

Replace "/path/to/your/directory" with the desired directory path.

Example

$ python3 dir_space_calculator.py
Total size: 123456789 bytes

Limitations

  • Symbolic Links: The script does not currently account for symbolic links. It treats them as regular files and sums up their sizes.
  • Special Directories: The script ignores special directories such as . and .. but may still encounter issues if the target directory contains unusual filesystem structures.
  • Performance: The script may take a significant amount of time to run on directories with a large number of files or deep directory trees.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published