Python change users' directory

Viewed 523

Does anyone know how someone would use Python to change the current directory a user is in?

I am currently working on a Python script. This script will be used by a user in a terminal/terminal emulator. When certain criteria is met, the script would move the user to the correct directory. The issue I am running into is that I can move the working directory for the Python script, but once the script exits the user is still in the directory they ran the script from. Any ideas on how to achieve this?

3 Answers

This may not be the perfect solution but it can be useful. With this commands you will have a new cmd promt open with the path in it. pd: only for windows users

import subprocess
import os
os.chdir('the\path\to\your\dir')
subprocess.run("start cmd", shell=True)
Related