You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import os
def file_count(directory):
"""
Returns a count of the number of files in a directory
"""
count = 0
for root, dirs, files in os.walk(directory):
for file in files:
count = count + 1
return count
FILE AGE
import datetime, os
def filesystem_age_days(fname=''):
"""Returns the age in days of the file or folder given as a parameter"""
if not fname:
return 0 # No files in directory; fname is blank
st = os.stat(fname)
dt_modified = datetime.datetime.fromtimestamp(st.st_mtime)
# calc age
now = datetime.datetime.now()
age = convert_dt_seconds((now - dt_modified).seconds)
return age
The text was updated successfully, but these errors were encountered:
FILE COUNT in a directory:
FILE AGE
The text was updated successfully, but these errors were encountered: