Learning a python I'm working on a generic utility script to recurse any directories below and spit filenames and other properties into a file - on Windows right now. I keep getting errors as below and I don't care about these files which appear to be found in "dot directories" so far. Manually listing directories to directories.remove() is fun whack-a-mole but I need better. I can't figure out how to just tell it to ignore all dot directories.
file_size = os.path.getsize(filename)
File "C:\Program Files\Python37\lib\genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'COMMIT_EDITMSG'
Here's where I am
import os
import time
# pip install --user hurry.filesize
from hurry.filesize import size
path = "./"
for root, directories, filenames in os.walk(path):
if ".*" in directories:
directories.remove(".*")
for filename in filenames:
file_path = os.path.join(root, filename)
file_size = os.path.getsize(filename)
better_changetime = time.strftime(
"%Y-%m-%d %H:%M:%S", time.gmtime(os.path.getmtime(filename))
)
fprops = file_path + " | " + better_changetime + " | " + size(file_size)
print(fprops)