forked from olovholm/NIME
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenamer.py
29 lines (24 loc) · 934 Bytes
/
renamer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/python
#
# This scripts runs through the folder 'nime/web/2012' and renames the pdf documents to convention.
# Scripts named 'XXX_Final_Manuscript.pdf' are renamed to 'nime2012_XXX'
#
import os
dir_path = "nime_archive/web/2012"
#iterates through each file in path 2012
for file in os.listdir(dir_path):
lfile = os.path.join(dir_path, file)
if os.path.isfile(lfile):
#extracts id_number from pdf file
num = file.split('_')[0]
#prepends correct number of zeros if name less than tre digits (treated as strings) e.g 2 becomes 002
if len(num) == 2:
num = "0%s" % num
elif len(num) == 1:
num = "00%s" % num
#generates destination file
destfile = dir_path+"/nime2012_%s.pdf" % num
#renames
os.rename(lfile,destfile)
#prints notification
print "File: %s \t renamed to: %s." % (lfile, destfile)