Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:41:13+00:00 2026-06-13T13:41:13+00:00

I keep getting a ‘cannot find file’ error when trying to run this. Why

  • 0

I keep getting a ‘cannot find file’ error when trying to run this. Why is it not finding and assigning the absolute path? Here is my code:

    file = "/" + arr[2] + ".exe"
    print(file)
    path = os.path.abspath(file)
    print(path)
    subprocess.Popen(path)
    localtime = time.asctime(time.localtime(time.time()))
    print(arr[2] + " opened at " + localtime + "\n")

Here is what is outputted:

/firefox.exe
C:\firefox.exe
Traceback (most recent call last):
File "C:\Python33\lib\subprocess.py", line 1090, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

I am trying to programmatically find open a program based on user input… Maybe I am going about that the wrong way, but this is how somebody suggested doing it. Firefox.exe should be located at C:/Program Files/Firefox/firefox.exe

Any help would be great! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:41:15+00:00Added an answer on June 13, 2026 at 1:41 pm

    One solution for attempting to open a program on Windows is to just search all folders, starting from the base directories of C:/Program files/ and C:/Program Files (x86). A simple solution to this might be something like the following:

    for program_files in (os.path.join("C:", "Program\ Files"), os.path.join("C:", "Program\ Files\ (x86)"):
        for dir in os.listdir(program_files):
            if os.path.exists(os.path.join(program_files, dir, arr[2]) + ".exe"):
                subprocess.Popen(os.path.join(program_files, dir, arr[2]) + ".exe")
    

    This only walks one directory down into the Program Files directories, but it should at least give a gist of what needs to be done, as well as provide a simple solution for most cases. I would assume that most programs tend to keep their executable under the first directory.

    As a quick side note: if you are creating an application that can be run on both 32bit and 64bit versions of Windows, you will want some kind of check for the existence of the Program Files (x86) directory, or some kind of check for 32 vs 64 bit Windows. That folder only exists on 64 bit versions of Windows.

    Also: the reason your method didn’t work is because you were getting the abspath of /firefox.exe, which on a Unix system signifies the lowest-level directory on the computer. On Windows, that would be C:/. Python generally works in a very Unix-ey way, so it assumes you wanted the root directory of your system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error saying that it cannot find my javascript function checkpw().
I keep getting this error: Could not load file or assembly 'Facebook, Version=5.4.1.0, Culture=neutral,
I keep getting this error when trying to run the code: (let ((exp lambda
Keep getting this error after inserting a subdatasheet into a query and trying to
I keep getting this error mesage when trying to add a breakpoint in gdb.
i keep getting an error: The upsizing wizard does not work with this version
I keep getting the following error: $ ./test.py -bash: ./test.py: cannot execute binary file
I keep getting this error and i have been trying everything for about a
I keep getting this whenever I run the below code: Fatal error: Call to
I keep getting this error when trying to do a git pull or a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.