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
14
votes
3 answers

Python raising FileNotFoundError for file name returned by os.listdir

I was trying to iterate over the files in a directory like this: import os path = r'E:/somedir' for filename in os.listdir(path): f = open(filename, 'r') ... # process the file But Python was throwing FileNotFoundError even though the…
Aarushi Mishra
  • 672
  • 1
  • 7
  • 20
13
votes
10 answers

external framework File/File.h (Parse/Parse.h) file not found

So every time I update my app, Xcode claims not to be able to find a particular external framework even though it's there. It's happened again with Xcode 6 and my usual methods (I'm fairly inexperienced, so these basically involve clicking and…
Joel Derfner
  • 2,207
  • 6
  • 33
  • 45
13
votes
1 answer

OPTIONS request authentication

I am developing a web application. It is using Basic authentication. It must process OPTIONS requests. These are web browser preflight requests as well as feature-support requests from WebDAV clients. As far as I understand OPTIONS request must be…
IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98
12
votes
2 answers

TS-Node: Could not find sourceFile

My project has been using ts-node to run a mix of JavaScript and TypeScript. Recently it stopped working, without an obvious reason. At the most simple level, here is how it's run and the error it produces: $ TS_NODE_PROJECT=./tsconfig.json…
Jonah
  • 9,991
  • 5
  • 45
  • 79
12
votes
2 answers

PyInstaller: a module is not included into --onefile, but works fine with --onedir

I'm using PyInstaller to bundle my application into one .exe file. The problem is that it works fine with --onedir option, but can't find a module when built with --onefile. Both --onedir and --onefile say during the building process: <...> INFO:…
Kuz
  • 131
  • 1
  • 1
  • 4
10
votes
5 answers

Error "no such file to load" -- sqlite3/sqlite3_native (LoadError)

My OS is Windows 7. My problem is that when I try to run rails server, an error occurs. I have installed the sqlite3 gem, even the sqlite-ruby gem, and still nothing. I already don't know what to do anymore. If anyone needs any additional…
10
votes
2 answers

ptrace on iOS 8

I'm trying to call a function on ptrace like thisptrace(PT_DENY_ATTACH, 0, 0, 0); But when I try to import it using #include Xcode gives me an error 'sys/ptrace.h' file not found. Am I missing something, do I need to import a library…
imas145
  • 1,959
  • 1
  • 23
  • 32
10
votes
1 answer

System.ComponentModel.Win32Exception when starting process - file not found, but file exists

I am trying to create a manager for my autostarts. It should read an XML file and then start my programs with a custom delay. For example: Realtek Audio Manager C:\Program…
pascalhein
  • 5,700
  • 4
  • 31
  • 44
9
votes
2 answers

pip install pygame - SDL.h file not found

MacOS Sierra ➜ fun_python $ pip --version pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (python 3.5) pip install pygame is giving me the following error: src/scrap.c:27:10: fatal error: 'SDL.h' file…
AKS
  • 16,482
  • 43
  • 166
  • 258
9
votes
3 answers

The system cannot find the path specified with FileWriter

I have this code: private static void saveMetricsToCSV(String fileName, double[] metrics) { try { FileWriter fWriter = new FileWriter( System.getProperty("user.dir") + "\\output\\" + …
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
8
votes
1 answer

FileNotFoundError: [WinError 2] The system cannot find the file specified - when saving a mp4 plot, WinPython, Anaconda

I have the code below, when I run it, the next error appears "FileNotFoundError: [WinError 2] The system cannot find the file specified". I have added the the logfile snippet. The wierd thing is, this code was working perfect yesterday, with…
Iulia_Vascan
  • 87
  • 3
  • 10
8
votes
1 answer

~Pods/Headers/Public/Google/Google/SignIn.h:1:9: 'GGLCore/GGLCore.h' file not found

OS 10.10.5 xcode 7.2 Objective-C iOS 9.2 CocoaPods 1.0.1 pod 'GoogleMaps' pod 'Google/SignIn' pod 'FBSDKCoreKit' pod 'FBSDKLoginKit' pod 'FBSDKShareKit' pod 'AFNetworking' pod 'MBProgressHUD', '~> 0.9.2' pod 'CardIO' pod "PubNub" ERROR, in file…
afyzgh
  • 81
  • 3
7
votes
0 answers

Cx_freeze fails when trying to add an Icon: [WinError 2] The system cannot find the file specified

This is a very interesting problem, I was attempting to add an icon to my cx_freeze executable but whenever I do it crashes, Note: I'm running windows 10 and using python 3.8.2 My setup.py file is as follows: from cx_Freeze import setup, Executable…
7
votes
5 answers

What are the most helpful features of effective 404 File Not Found error pages?

When a user comes across your site's 404 File Not Found error page, it is most likely not what they were looking for. Here, you have the opportunity to turn a dead end into a resource that can help your visitor find whatever they were looking…
Joe Lencioni
  • 10,231
  • 18
  • 55
  • 66
7
votes
1 answer

Cannot open include file config.h

One of the header files uses #include but I keep getting the error Fatal error C1083: Cannot open include file: 'config.h': No such file or directory and I don't know why. config.h is in the headers folder in the project and when I…
SSEMember
  • 2,103
  • 4
  • 20
  • 28
1
2
3
40 41