I trying to find and move resumes in PDF and DOC formate to different directories, PDF files in /PDF
dir and DOC files in /DOCX
dir. My concerns are;
Are my regular expressions for finding the PDF and DOC files correct? The resumes are named as for example,
john right ResumeQA.doc
,abcResumeC.doc
,ShawnResume.pdf
,johnright_ResumeQA.pdf
I am not getting any counts or outputs on IDE nor in the output file.
Code that I came up with is below:
import os, sys, re
countpdf, countdoc = 0, 0
pdf = re.compile(r'\b\w*{resume}\w*\.[pdf]\b')
docx = re.compile(r'\b\w*{resume}\.[doc]\b]')
#os.mkdir(r'/Users/Desktop/Networking materials/PDF')
pdfdir = os.path.dirname(r'/Users/Desktop/Networking materials/PDF/')
print pdfdir
#os.mkdir(r'/Users/Desktop/Networking materials/DOCX')
docxdir = os.path.dirname(r'/User/Desktop/Networking materials/DOCX/')
print docxdir
out = sys.stdout
with open('output.txt', 'w') as outfile:
sys.stdout = outfile
for rdir, directory, files in os.walk(r'/Users/Desktop/Networking materials/'):
match1 = re.findall(pdf, str(files))
print match1
for items1 in match1:
os.chdir(pdfdir)
countpdf +=1
print countpdf
match2 = re.findall(docx, str(files))
print match2
for items2 in match2:
os.chdir(docxdir)
countdoc +=1
print countdoc
sys.stdout = out
The only output that I get so far is:
/Users/Desktop/Networking materials/PDF
/Users/Desktop/Networking materials/DOCX
Could anyone of you please correct my code and if possible please suggest a more efficient way to accomplish this task.