I edited this post so that i could give more info about the goal I am trying to achieve.
basically I want to be able to open VSCode in a directory that I can input inside a python file I am running trhough a shell command i created.
So what I need is for the python file to ask me for the name of the folder I want to open, pass that information to the terminal so that it can then cd into that folder and open vscode automatically.
I tried with os.system() that is, as I read, one of the ways I can achieve that goal.
The problem is that if I use standard commands like os.system('date') or os.system('code') it works without any problem.
If I try to use os.system(cd /directory/) nothing happens.
As suggested I also tryied with subprocess.call(["cd", "/home/simon/Desktop"])
but the terminal gives me the error: FileNotFoundError: [Errno 2] No such file or directory: 'cd'
I am going to include both the python file:
import os, subprocess
PATH = "/home/simon/Linux_Storage/Projects"
def main():
print("\n")
print("********************")
for folder in os.listdir(PATH):
print(folder)
print("********************")
project = input("Choose project: ")
print("\n")
folders = os.listdir(PATH)
while project:
if project in folders:
break
else:
print("Project doesn't exist.")
project = input("Choose project: ")
os.system(f"cd /home/simon/Linux_Storage/Projects/{project}")
if __name__ == "__main__":
main()
and the shell script (maybe I should change something here):
function open() {
python3 .open.py
code .
}