the goal is to identify an extension and output two different text files depending on whether a .LOG file is present or not in a directory. Here is what I have so far.
fp = '/home/path/to/file'
for content in fp:
ext = os.path.splitext(content)[-1].upper() # splits root from extension
if ext != ".LOG":
with open(os.path.join('/home/path/to/file','Errorfile'),'w') as f:
f.write('.LOG file not found')
elif ext == '.LOG':
with open(os.path.join(/home/path/to/file' ,'Correctfile') , 'w') as T:
T.write('There is a .LOG file in directory)
The code just outputs the Errorfileand nothing past f.write line gets executed. My guess is its probably the way I structured my conditional statements. Any help would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire