I've been working on this bit of code trying to open multiple files in a directory. The directory contains 10 text files. I want to open each of the files, do some stuff to it (namely remove stop words) and output the transformed text into a new file in a different directory. However, I have this problem:
FileNotFoundError: [Errno 2] No such file or directory: '1980'
The file definitely exists in the directory and I have been giving the absolute path. I have looked at the current working directory before opening the file and it does not return the absolute path I gave it, rather the directory where this project is located. Any help in getting the code to open the necessary files and write the result to the output file would be greatly appreciated! Here is my code:
path = 'C:/Users/User/Desktop/mini_mouse'
output = 'C:/Users/User/Desktop/filter_mini_mouse/mouse'
for root, dir, files in os.walk(path):
for file in files:
print(os.getcwd())
with open(file, 'r') as f, open('NLTK-stop-word-list', 'r') as f2:
x = ''
mouse_file = f.read().split() # reads file and splits it into a list
stopwords = f2.read().split()
x = (' '.join(i for i in mouse_file if i.lower() not in (x.lower() for x in stopwords)))
with open('out', 'w') as output_file:
output_file.write((' '.join(i for i in mouse_file if i.lower() not in (x.lower() for x in stopwords))))