Questions tagged [file-not-found]

An error, exit status, or exception that indicates that the file denoted by a specified pathname could not be found.

An error, exit status, or exception that indicates that the file denoted by a specified pathname could not be found. In other words, you're trying to access a file that doesn't exist where the code is expecting it to be.

This could occur as a result of many different actions, such as...

  1. The file doesn't actually exist, or was deleted before you could access it
  2. There is a spelling mistake in your pathname, or the pathname contains characters that aren't permitted in the pathname.
  3. You're using a relative pathname (such as file.txt) and the file doesn't exist in the default working directory for your application
  4. The code is getting confused due to different directory path indicators on different operating systems (ie / vs \)
  5. The programming language interprets the \ character in a String to be a escape character for a special symbol (such as \n indicating new-line), and you're using single \ slashes as directory indicators instead of \\ for a single escaped slash.
  6. In some languages, it could also give this exception if you aren't able to access the file due to security permissions.

Your code should be able to prevent or handle this condition, such as by doing the following...

  1. Detect - Many programming languages allow you to create a File object as a virtual representation of a physical file. Further to this, you can usually call a method or function that asks whether the file exists, such as exists();. This would allow you to check the file exists before you attempt to access it
  2. Prevent - If the user is selecting a file, present them with a FileChooser dialog rather than a text entry field. FileChooser dialogs echo the files that exist in the system, so spelling mistakes are avoided. If you're using relative paths, convert them to absolute paths if practical, or ensure you set the relative path location to a known directory before trying to access files relatively.
  3. Handle - Wrap your file access methods in exception-handling code, such as a try-catch block. This will allow you to catch unexpected exceptions, and perform an alternate operation, such as alerting the user of the error.
601 questions
2
votes
2 answers

FileNotFoundError When uploading to S3 using Flask

I am trying to upload files to amazon s3 and I keep on getting FileNotFoundError: [Errno 2] No such file or directory: -filename- error, init.py from flask import Flask, render_template, request, redirect from werkzeug.utils import…
snigcode
  • 365
  • 4
  • 17
2
votes
2 answers

How did I read the .gz file with colab

I am a beginner in python, I am working with Google colab, I downloaded a .gz file and saved it in my desktop from MNIST database, when I want to read this file: import tensorflow as tf import zipfile with…
abidi hedi
  • 21
  • 1
  • 2
2
votes
0 answers

Python: Cx_Freeze FileNotFoundError: Errno 2 in library.zip

I want to build my python script with Cx_Freeze, however i get this error : FileNotFoundError: [Errno 2] File b'C:\Users\...\build\exe.win323.8\lib\library.zip/table.csv' does not exist:…
2
votes
1 answer

Python: FileNotFoundError not caught by try-except block

recently i started learning Python and encountered a problem i can`t find an answer to. Idea of the program is to ask for username, load a dictionary from JSON file, and if the name is in the dictionary - print the users favourite number. The code,…
Ni3dzwi3dz
  • 177
  • 8
2
votes
2 answers

OSError: file not found

I'm trying to write a script that needs to rename (in the script itself, not in the folder) some .txt files to be able to use them in a loop, enumerating them. I decided to use a dictionary, something like this: import os import fnmatch dsc =…
novich
  • 79
  • 2
  • 7
2
votes
0 answers

The problem with using #include and MSVC 2017

I have run into a problem with including into my project, in spite of the fact that I have set the language of the project to "ISO C++ Latest Draft Standard (/std:c++latest)" in "MSVS 2017". Any help will be appreciated. It is worth mentioning that…
2
votes
3 answers

Dockerized spring-boot web service throws FileNotFound Exception

I have tried to copy files from my windows machine to Docker container using the Docker File Command and reading those files from spring web service . Webservice throws an error file not found! Here I am trying to copy my local directory src/nlp to…
2
votes
1 answer

FileNotFoundError in Python during Arabic text analysis

I have a folder has 150 Arabic text files. I want to find the similarities between each other. how can I do that? I tried what explained here from sklearn.feature_extraction.text import TfidfVectorizer documents = [open(f) for f in…
Nujud Ali
  • 135
  • 2
  • 9
2
votes
2 answers

System.IO.FileNotFoundException: Could not load assembly "AppName" after update xamarin forms

I can't rebuild the project and I'm getting this exception after updating to latest Xamarin Forms 3.4.0.1008975 , if I downgrade it to 3.1.0.583944 or lower the exception will gone and I can build successfully. I've tried to update VS and clean -…
2
votes
0 answers

Python code won't open file in virtual studio code

So I have an assignment for college in python and for a part of it, I need to open the file "voting.txt". I coded up the assignment in Pycharm, as that's the IDE we use in college, but my preferred IDE is VSCode. In Pycharm the code works fine. I…
ConorH99
  • 25
  • 6
2
votes
3 answers

FileNotFoundError: [Errno 2] No such file or directory: 'frame0.png' but actually has

I have a similar problem to many post about the path problem but I cannot find any solution to fix my problem So first, I have a function where I create a directory which will store all extracted frames from video def extract_frame(video,folder): …
emp
  • 602
  • 3
  • 11
  • 22
2
votes
1 answer

Json file was not found by webpack

I am developing a small personal project, i need to import json files with webpack but impossible package.json contain: "webpack": "^4.17.1" "json-loader": "^0.5.7", webpack.config.js contain { test: /\.json$/, use: 'json-loader' }, I dont…
terapha
  • 21
  • 1
  • 4
2
votes
1 answer

FileNotFoundError \Microsoft SDKs\Windows\v8.1\lib

While trying to install PyNacl, i run into this error: FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1\\lib' Which then leads to this: Command "python setup.py…
Deviatenorm
  • 31
  • 1
  • 3
2
votes
2 answers

directive don't exist in current component

I'm new to angular 2, I saw some videos and implement this but I am facing some problems. I have created a new component navbar and imported it in app.component.ts file. While adding meta data @Component directive not found error occurred. Error:…
Striker
  • 61
  • 1
  • 9
2
votes
2 answers

android.content.res.Resources$NotFoundException: File res/mipmap-xhdpi-v4/ic_copyright_black_24dp.png from xml type xml resource ID #0x7f0d0007

Hi all I am making a about us page in my android app with the help of gitLibaray. this is the library i m using The code works fine but the issue is when i am trying to show the copyright logo it gives me error i have add the stack track…