I have the following code that should read all the .txt files in the folder where my project is located (I'm doing it in Visual Studio Code):
for file in glob.glob("*.txt"):
fp = open(file, "r", -1, 'utf-8')
text= fp.readlines()
print(file, "->", text)
I would like to read all the files (without informing the directories) .txt that are in my folder but this function is somehow not working in Visual Studio, but it works perfectly in Jupyter notebook.
Output/Content of the text
variable in jupyter notebook
file1.txt -> ["this phrase is in file 1"]
file2.txt -> ["this phrase is in file 2"]
file3.txt -> ["this phrase is in file 3"]
Does anyone know if I'm forgetting a Visual Studio function or configuration or is there another function that does this?