Relative file paths are resolved from the process’s current working directory, which may differ from the folder containing your script. Print the path Python is actually checking before moving files around.
Inspect the target
from pathlib import Path
path = Path("data.txt")
print("Working directory:", Path.cwd())
print("Checking:", path.resolve())
print("Is a file:", path.is_file())Run the code from the same terminal, IDE or scheduled job that shows the error. Compare the printed location with the file’s actual location and extension. Watch for capitalization on case-sensitive filesystems and hidden extensions such as data.txt.txt.
Read a file beside a saved script
from pathlib import Path
path = Path(__file__).resolve().parent / "data.txt"
print(path.read_text(encoding="utf-8"))This ties the path to the script. __file__ is normally available in a saved script, but not in a plain interactive session or notebook cell. In those environments, choose an explicit project path or inspect Path.cwd().
Read the exception accurately
FileNotFoundError, PermissionError and IsADirectoryError describe different failures. A missing file and a file you cannot read need different fixes. On Windows, use Path components or a raw string for backslash paths to avoid accidental escape sequences.
If the terminal produces no output at all, see silent Python scripts. For the equivalent issue in a shell script, see PowerShell missing paths.
Sources and verification
Working-directory and script-relative examples are executed with disposable files in the local Python verification run.
