I want to build a script that does the following:
The script should do make an arry from the directory where the script is with os.listdir(). Then the script has to test if the value in the array already excists in the outcome file, if not the name in the array should be written to the file alphabetically.
The outcome in my file should be:
Could anyone please help me to make a script like this?
I already started making this: But the problem with this is. That everything is written to 'films.txt' and nothing is checked if the name in lijst_films already excists in 'films.txt'
import os,sys,re lijst_films=os.listdir() file='films.txt' if not os.path.exists(file): file=open('films.txt','w') file.close() for x in lijst_films: print(x) x=re.sub('20\d\d*.*', '', x) x=re.sub('1080*.*', '', x) x=re.sub('\(' ,'' ,x) x=re.sub('\)' ,'' ,x) x=x.replace('.'or'',' ') x=x.replace('[isoHunt]','') if x[-1] == ' ': x=x.replace(x,x[:-1]) if x[-0] == ' ': x=x.replace(x,x[1:]) print(x) with open('films.txt','a') as file: file.write('%s\n' %(x))
Thank you in advance.