I try to loop through folder and read files but only the first file will open and read correctly but the second files print the name and through an error "IOError: [Errno 2] No such file or directory:". I have tried the following
for filename in os.listdir("pathtodir\DataFiles"):
if filename.endswith(".log"):
print(os.path.join("./DataFiles", filename))
with open(filename) as openfile:
for line in openfile:
........
./DataFiles, according to the line of code that retrieves the list frompathtodir\DataFiles. You should first figure out where you're looking for the files at, settle on a forward or backslash (but not both), and then be consistent when you use that pathname. You have to open the file in the same folder you got it's name from; your code does not do that, because it tries to openfilenamewithout a path. The code you're using tries to access the same file in three separate locations, and it's only in one of them.