I am writing a python script to give me the sizes of my directory and subdirectories. I am getting the following error.
=======================
AMD
Bytes: 23917297664
Megs: 22809.3125
Gigs: 22.27471923828125
Traceback (most recent call last):
File "c:\users\user\desktop\temp3.py", line 13, in <module>
sum(os.path.getsize(f) for f in os.listdir(dir) if os.path.isfile(f))
PermissionError: [WinError 5] Access is denied: 'Documents and Settings
Here is my code
import os
dir_size = sum(os.path.getsize(f) for f in os.listdir('.') if os.path.isfile(f))
print(os.getcwd())
print(os.listdir('.'))
print("\tBytes: {}".format(dir_size))
print("\tMegs: {}".format(dir_size/1048576))
print("\tGigs: {}".format((dir_size/1048576)/1024))
dirs = os.listdir('.')
for dir in dirs:
if "$" not in dir:
sum(os.path.getsize(f) for f in os.listdir(dir) if os.path.isfile(f))
print("=======================")
print("\t{}".format(dir))
print("\t\tBytes: {}".format(dir_size))
print("\t\tMegs: {}".format(dir_size/1048576))
print("\t\tGigs: {}".format((dir_size/1048576)/1024))
I am the only user on the system, I am the Administrator so I thought I should of course have permissions to see everything. Any ideas?
As a side note: PermissionError: [WinError 5] Access is denied python using moviepy to write gif has been suggested as a similar solution/question, below I explain why this is not the case.
Not the same, the solutions provided do not apply here. I am admin, I am running it as admin, and I am not using the moviepy lib