Skip to content

Instantly share code, notes, and snippets.

@attibalazs
Created May 5, 2016 13:41
Show Gist options
  • Save attibalazs/d1f9237befd0a0be1c23aef2e2a1dcf3 to your computer and use it in GitHub Desktop.
Save attibalazs/d1f9237befd0a0be1c23aef2e2a1dcf3 to your computer and use it in GitHub Desktop.
Python script to do a file listing and log basic attributes to a csv file
import sys, os, time, csv
data_dir = os.path.join(os.getcwd(), os.pardir, 'data')
sys.path.append(data_dir)
with open(os.path.join(data_dir, "listing.csv"), 'w') as csvfile:
writer = csv.writer(csvfile)
row = ('path', 'modified_date', 'last_accesed_date', 'size')
writer.writerow(row)
for root, directories, filenames in os.walk('c:\\temp\\'):
for filename in filenames:
path = os.path.join(root, filename)
try:
info = os.stat(path)
row = path, time.ctime(info.st_mtime), time.ctime(info.st_atime), info.st_size
except WindowsError:
row = path, 'unknown', 'unknown', 'unknown'
print row
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment