Function for examine content of directory
Tigerstyle
laddosingh at gmail.com
Fri Sep 7 10:28:03 EDT 2012
Ok I'm now totally stuck.
This is the code:
---
import os
from collections import Counter
path = ":c\\mypath\dir"
dirs = os.listdir( path )
filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"}
extensions = []
for filename in filenames:
f = open(filename, "w")
f.write("Some text\n")
f.close()
name , ext = os.path.splitext(f.name)
extensions.append(ext)
# This would print all the files and directories
for file in dirs:
print(file)
for ext, count in Counter(extensions).items():
print("Count for %s: " % ext, count)
---
I need to make this module into a function and write a separate module to verify by testing that the function gives correct results.
Help and pointers are much appreciated.
T
More information about the Python-list
mailing list