Skip to content

Instantly share code, notes, and snippets.

@pragmaticobjects
Created March 12, 2011 06:39
Show Gist options
  • Select an option

  • Save pragmaticobjects/867091 to your computer and use it in GitHub Desktop.

Select an option

Save pragmaticobjects/867091 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys, os, time
def listFiles(val):
curdir = os.getcwd()
files = []
for filename in os.listdir(curdir):
if (not filename.startswith('.')):
s = os.stat(os.path.join(curdir, filename))
lastmodified = time.strftime("%Y-%m-%d %I:%M %p", time.localtime(s.st_mtime))
size = os.path.getsize(os.path.join(curdir, filename))
isdir = os.path.isdir(os.path.join(curdir, filename))
if isdir is True:
filesize = ""
else:
if size < 1000:
filesize = "1 KB"
elif size < 1000000:
filesize = "%.2f %s" % ((size / 1000), ' KB')
else:
filesize = "%.2f %s" % ((size / 1000000), 'MB')
fileattr = {
'filename' : filename,
'isdir': isdir,
'filesize': filesize,
'lastmodified': lastmodified
}
files.append(fileattr)
return files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment