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
1 answer

Android - Can not find the file although it exists in the data folder?

I am trying to copy the SQLite database from the data folder to SDCard using Emulator, i am using below code, which i found here. try { File sd = Environment.getExternalStorageDirectory(); File data = Environment.getDataDirectory(); if…
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149
2
votes
0 answers

Textract - windows10 - shell error - failed with exit code 127

The below code works fine for txt file but doesn't work with pdf files. import textract text = textract.process(r'C:\Users\Python_files\accounts.txt') However, I cannot seem to figure out what the problem is in the below code snippet: import…
2
votes
1 answer

Python FileNotFoundError with os.listdir(sys.argv[1])

Building a malware classifier for a class and I am just trying to implement a loop that goes through every file in a folder using os.listdir() and I specified that the folder is the given argv. I have been stuck on this problem for hours but I can't…
2
votes
2 answers

Azure databricks %run magic command unable to find file path

I have 2 notebooks under the root folder in my workspace. Calling one notebook from the other with %run magic cmd returns error saying file path not found. This is my command: %run /Users/name@comp.com/notebookB $arg1=val1 $arg2=val2
2
votes
4 answers

Why can't Matlab see my function?

My function is definitely working; it's tested and was at one point being recognized. Here's the function prototype: function [X Y] = calculateEllipse(x, y, a, b, angle) %# Code here end Here's the call I'm making from the Matlab…
user920761
  • 21
  • 1
  • 1
  • 2
2
votes
1 answer

Can't compile a Crow sample - boost/optional.hpp: No such file or directory

I'd like to compile and test Crow C++ microframework in Debian Linux 11: Download the latest crow.deb, currently crow-v1.0+1.deb. Install it: $ sudo dpkg -i crow-v1.0+1.deb Selecting previously unselected package crow. (Reading database ... 587955…
haba713
  • 2,465
  • 1
  • 24
  • 45
2
votes
1 answer

Dundas Charts File Not Found

I'm looking through a legacy system and have found that the Dundas charts throws a file not found exception quite often, but not all the time. The system has multiple servers picking up requests and it has therefore set Dundas to run using a server…
Bob
  • 3,074
  • 11
  • 43
  • 62
2
votes
2 answers

Can't read file from a C++ program on a Mac

First of all, this is part of my code: .... string input; getline(cin, input); ifstream openFile; openFile.open(input.c_str(), ios::in); if(openFile.is_open()){ cout << "File opened" << endl; } else { cout << "Cant open the file " <<…
LustSeeker
  • 21
  • 1
  • 1
  • 2
2
votes
1 answer

Iterating through directory error: FileNotFoundError: [Errno 2] No such file or directory

I wrote a script to iterate through multiple text files in a directory and count the words contained in each that are also contained in a dictionary file. I wrote and tested the script with two files in the directory, and got it working perfectly,…
claudiae
  • 35
  • 4
2
votes
0 answers

nextjs page not found after deployment

I created a simple nextjs app using create-next-app I added only some pages in pages folder (contact.js, help.js) I can build and start app in localhost using below commands npm run build npm run start this is script part of package.json "scripts":…
2
votes
0 answers

Sockeye - FileNotFoundError: Could not find module 'C:\Users\...\Anaconda3\lib\site-packages\mxnet\libmxnet.dll' (or one of its dependencies)

I want to train the model according to https://aws.amazon.com/blogs/machine-learning/train-neural-machine-translation-models-with-sockeye/ I'm using Anaconda 4.10.3 (Python 3.8.8) and I had already installed Sockeye and MXNet. As soon as I run the…
Ramón Wilhelm
  • 967
  • 2
  • 18
  • 39
2
votes
1 answer

Python: FileNotFoundError, from glob output, full path to file is correct

I hate to be the person to post another FileNotFoundError question, but most of them that I see are about not giving the full path to the file, that is not my problem here. I have a number of log files in folders in ../../Data/. I create a glob of…
Jerup
  • 21
  • 1
2
votes
2 answers

FileNotFoundError in PIL image with relative path and absoulute path

import PIL.Image as pilimg import numpy as np # Read image im = pilimg.open("../dataset/start.jpg") # Display image im.show() # Fetch image pixel data to numpy array pix = np.array(im) (I'm no the author of the dataset, so I couldn't upload…
Hyeonseo Kim
  • 324
  • 3
  • 15
2
votes
1 answer

How to manually set a CMake path variable to NOTFOUND?

I'm hardcoding a library path before hand and want to set the path to NOTFOUND manually if the file doesn't exist. set(MY_LIB "path that doesn't exist") if(NOT EXISTS "${MY_LIB}") message("not found") // set it back to NOTFOUND ?? endif() if…
puio
  • 1,208
  • 6
  • 19
2
votes
1 answer

Why do I get a FileNotFoundError when using subprocess?

My code: parser = xml.sax.make_parser() handler = WikiXmlHandler() parser.setContentHandler(handler) for line in subprocess.Popen(['bzcat'], stdin=open(path), stdout=subprocess.PIPE).stdout: …
Leon
  • 23
  • 1
  • 5