The location of this script is on D:
The script works for drives other than D:
On D: the script does not start from the top folder
It starts from the script working directory
How to make it start from the root?
def folder_usage_one(folder):
from pathlib import Path
root = Path(folder)
return (sum(f.stat().st_size
for f in root.glob('**/*') if f.is_file()))
Try using "D:\" for referencing the root of the D drive instead of "D:"
More details on this similar Q&A : Why does pathlib.Path("C:") resolve to the working directory on Windows?