I am trying to loop through directories. My goal is to open the directory ff
for modifications in the files.
When I try open (ff, 'r')
it does not work.
Further, the files in the directories d.txt
has numbers and symbols x
, 1
, "
in every line. I am seeking to remove these characters from each line.
import os
filenames= os.listdir (".")
for filename in filenames:
ff = os.path.join(r'C:\Users\V\Documents\f\e\e\data', filename, 'd.txt')
f = open(str(ff),'r') #this line does not open the file
a = ['x','1','"']
lst = []
for line in f:
for word in a:
if word in line:
line = line.replace(word,'')
lst.append(line)
f.close()
The Error that I am getting:
for line in f:
ValueError: I/O operation on closed file.