I went across similar questions of renaming files in a directory using python.
I have these files in a directory which I want to rename:
-statistical_analysis_with_r
-statistical_pattern_recognition_3rd_edition
to
-Statistical Analysis With R
-Statistical Pattern Recognition 3rd Edition
For this I wrote this script in windows:
def naming(so):
import re
w=re.split('[ _]+',so)
r=[]
for i in w:
r.append(i.capitalize())
print(' '.join(r))
import os
for c in os.listdir(os.getcwd()):
if c.endswith(".pdf"):
os.rename(c,naming(c))
print(os.listdir(os.getcwd()))
But I am getting this error:
Statistical Analysis With R.pdf
Traceback (most recent call last):
File "<ipython-input-79-d7f645d6d3e5>", line 4, in <module>
os.rename(c,naming(c))
TypeError: rename: can't specify None for path argument
Can anybody help what's going on?
And any help doing same thing using R (www.r-project.org)?
Loads of thanks in advance.