0
import os
os.startfile('C:\\Some Location\\file.file')

When I am trying to run the above code the code gives an error as follows:- FileNotFoundError: [WinError 2] The system cannot find the file specified

While for the same location this code works perfectly for files with '.txt' extension. For eg,

import os
os.startfile('C:\\Some Location\\file.txt')

This runs perfectly and opens the file.

Please help me solve this issue, I think I am using the wrong extension for the file. The type of file is 'File'.

1
  • If Windows is saying the type is just 'File', I think that means it has no extension - try 'file' as the name. Or turn off the stupid Windows feature that hides the actual names of your files from you... Commented Aug 18, 2020 at 3:01

1 Answer 1

1

From the documentation for os.startfile: Start a file with its associated application.

Windows must have an association between the extension .file and some software. If not, Windows does not know what software to use.

Your .txt file is open in Notepad (or other), which is associated to the .txt extension files.

To add an association:

  • you could create a .file file somewhere on your system.
  • Then right click on it, and select Open with.
  • Select which software should handle .file extensions, check the "Always use this application for this type" (or something similar, I do not have a Windows to check).

Then next time you try to use os.startfile(), it will open the file.file with the chosen application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.