-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_run.py
25 lines (22 loc) · 1.03 KB
/
find_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import subprocess
import os
# Define a dictionary of file extensions and corresponding commands to run the files
commands = {
".py": ["python"], # For Python files, run using the Python interpreter
".js": ["node"], # For JavaScript files, run using the Node.js interpreter
".sh": ["bash"], # For shell script files, run using the Bash shell
".html": ["open"] # For HTML files, open them in the default web browser
}
# Prompt the user to enter the filename to run
filename = input("Enter the filename to run: ")
# Search for the file in the current directory and subdirectories
for root, dirs, files in os.walk("."):
if filename in files:
file_path = os.path.join(root, filename)
ext = os.path.splitext(filename)[1]
if ext in commands:
command = commands[ext] + [file_path] # Construct the command to run the file
subprocess.run(command) # Execute the command
break
else:
print(f"Error: file {filename} not found in current directory or subdirectories")