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.
- 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.)
-
Clone the repository:
git clone https://github.com/yourusername/dirspace-calculator.git
-
Navigate to the project directory:
cd dirspace-calculator
-
Ensure Python is installed:
- You can check your Python version by running:
python3 --version
- You can check your Python version by running:
To calculate the total size of all files in the current directory:
-
Run the script using Python:
python3 dir_space_calculator.py
-
The script will output the total size of all files in the 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.
$ python3 dir_space_calculator.py
Total size: 123456789 bytes
- 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.