ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Wanda_lin.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 1573 byte(s)
Log Message:
Initial Import

File Contents

# Content
1 ## Wanda.py
2 ## This program will elvolve into a colection of functions that will automate some of the things
3 ## Wanda does.
4 ## EBorges
5 ## 05.06.03
6
7 import os,sys
8
9
10 def CatalogueDir(arg, dirname, names):
11 for x in names:
12 fullFile = dirname + '\\' + x
13 if os.path.isfile(fullFile):
14 ext = x[-3:]
15 ext = ext.upper()
16 o = open(arg + '\\' + ext + '.txt','a')
17 o.write(fullFile + '\n')
18 #o.close()
19
20 def ReportFindings(workDir,reportFile):
21 print "These are the final results:\n"
22 print "-"*20
23 print "\n"
24 for file in os.listdir(workDir):
25 o = open(workDir + '\\' + file, 'r')
26 output = o.readlines()
27 o.close()
28 print 'There are %d %s files'%(len(output),file[:-4])
29 i = open(reportFile + '.csv','a')
30 input = file[:-4] + ',' + str(len(output))
31 i.write(input + '\n')
32 i.close()
33 print "\nThese results have also been saved in %s" % reportFile
34
35 def ClearWorkDir(workDir):
36 if os.path.exists(workDir):
37 for i in os.listdir(workDir):
38 os.remove(workDir + '\\' + i)
39 os.rmdir(workDir)
40 os.mkdir(workDir)
41
42 if __name__ == "__main__":
43 reportFile = '/home/knoppix/tmp/CataLogContents.csv'
44 workDir = /home/knoppix/tmp/
45 workDir = workDir + '\\' + 'Wanda'
46 ClearWorkDir(workDir)
47 mainDir = "/mnt/hda1"
48 print "Now scaning directories and cataloging files...\n"
49 os.path.walk(mainDir,CatalogueDir,workDir)
50 ReportFindings(workDir,reportFile)