ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/EB_FileRenamer.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: 1910 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 """
2     EB_FileRenamer.py
3    
4     A simple file renamer that will traverse subdirectories and append a sequential number to the
5     front of the file name.
6    
7     Eborges
8     5.11.05
9     """
10    
11     import os
12    
13    
14     class Counter:
15     def __init__(self, count = 1):
16     """Nino's main Counter Class. It will allow you to keep the counter in memory and you can
17     count in multiples. For example if you pass it 2 and inc by 2, your counting in multiples
18     of 2"""
19     #self.count = 1
20     self.count = count
21     def inc(self, n=1):
22     self.count += n
23    
24     def AppendSeq(args, dirName, filesInDir):
25     count = args[2]
26     #localCount = count.count
27     #count = 1
28     for file in filesInDir:
29     if os.path.isfile(dirName + "\\" + file):
30     seqNumber = "%0*d"% (args[1],count.count)
31     #print seqNumber
32    
33     ## Remove this line after this proj. This was only a temp changing of the file var.
34     file2 = file.split("Privileged & Confidential and Not Subject to FOIA - ")[1]
35    
36     #seqNumber = "%0*d"% (args[1],count)
37     os.rename(dirName + '\\' + file, 'C:\\Documents and Settings\\eborges\\Desktop\\Working\\Comstore\\DOEIG024\\' + args[0] + str(seqNumber) + " Privileged & Confidential and Not Subject to FOIA - " + file2)
38     #os.rename(dirName + '\\' + file, dirName + '\\' + args[0] + str(seqNumber) + "_" + file)
39     #localCount = localCount + 1
40     #count = count + 1
41     count.inc(1)
42     #raw_input("test")
43     #localCount = localCount -1
44     #count.inc(localCount)
45    
46    
47     if __name__ == '__main__':
48     startDir = r'C:\Documents and Settings\eborges\Desktop\Working\Comstore\DOEIG024'
49     # A string to append and what base to start at.
50     count = Counter(733529)
51     appendation = ['DOE-IG_',7,count]
52     os.path.walk(startDir, AppendSeq, appendation)