Change directory in python

-1

I need to change directory to execute a command, looking for several alternatives but none works, in all I get "No such file or directory". I run the script on a server, from nginx. The script that I run is in / var / www / folder1 / test, and the directory I need to go to is / var / www / folder2 / subfolder

    
asked by Shami Cooper 24.01.2018 в 23:57
source

1 answer

0

If you are using the os python library you should know the current working directory where your script runs, like this:

import os

print os.getcwd() #esto te permite conocer el directorio actual
os.chdir("/var/www/carpeta2/subcarpeta") # la ruta absoluta
#una vez ubicado en el directorio adecuado puedes ejecutar el comando 
    
answered by 25.01.2018 / 00:24
source