I'm new to python and i am trying to split the filenames that i have read from a directory. I could split the file names from the extension but splitting the name is what i want. Here is my code...can you help me on how to do this. I want to split error log and December with the date( i.e into two parts with error in one and date time into 2nd part.
import os
import os.path
path = 'C:\\Users\\abc\\Desktop\\xls'
text_files = [os.path.splitext(f)[0] for f in os.listdir(path)]
print (text_files)
r = str(text_files)
f = "C:\\Users\\abc\\xls"
f = open('output.txt', 'w')
f.write(r)
f.close()
The exact names of files in the directory are :
- Error_Log_December_10_2016_06_19_05 PM.txt
Error_Log_December_15_2016_06_19_05 PM.txt
around 50 files are present like this which are to be split. Please help.