'FileNotFoundError: [Errno 2] No such file or directory: '/content/gdrive/MyDrive/data files\\URL_ID_1.txt'
# Folder Path
path = "/content/gdrive/MyDrive/data files"
# Change the directory
os.chdir(path)
# Read text File
def read_text_file(file_path):
with open(file_path, 'r') as f:
info=f.read()
stop_words(info)
# iterate through all file
for file in os.listdir():
# Check whether file is in text format or not
if file.endswith(".txt"):
file_path = f"{path}\{file}"
# call read text file function
read_text_file(file_path)
I get this error:
FileNotFoundError Traceback (most recent call last)
<ipython-input-139-07ff61fe2c38> in <module>()
22
23 # call read text file function
---> 24 read_text_file(file_path)
<ipython-input-139-07ff61fe2c38> in read_text_file(file_path)
10
11 def read_text_file(file_path):
---> 12 with open(file_path, 'r') as f:
13 info=f.read()
14 stop_words(info)
FileNotFoundError: [Errno 2] No such file or directory: '/content/gdrive/MyDrive/data files\\URL_ID_1.txt'
Solution 1:[1]
This might be happening due to linux, windows inconsistency, you should add your file path as
file_path = os.path.join(path,file)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abhinay Yadav |
