I am trying to get the files names from a list of file locations. Thinking it involves string slicing.
The one I worked out is:
L = ['C:\\Design\dw\file4.doc',
'C:\\light\PDF\downloads\list.doc',
'C:\\Design\Dq\file4g.doc',
'C:\\Design\Dq\file4r.doc',
'C:\\Design\Dq\file4k.doc',
'C:\\Design\Dq\ole.doc',
'C:\\GE\easy\file\os_references(9).doc',
'C:\\mate\KLO\Market\BIZ\KP\who\Documents\REF.doc']
LL = []
for a in L:
b = a.split('\')
for c in b:
if c.endswith('.doc'):
c.replace('.doc', '')
LL.append(c)
print LL
question 1: the output still contains ‘.doc’. why, and how can I have them removed?
question 2: what’s the better way to get the file names?
Thanks.