-4

I need to change the directory in the cmd with the command cd. For example cd users/desktop. But when I run the script, nothing happens.

I have already tried with the following commands:

  • os.chdir("cd Documents/archive")
  • os.system("cd Documents/archive")

but neither of them works, just nothing happens.

How do you navigate in the directories with Python?

wovano
  • 3,264
  • 4
  • 18
  • 43
Jhonatan Zu
  • 157
  • 1
  • 2
  • 8

1 Answers1

0

You can check the current directory using

os.getcwd()#gives you the directory in which you are in

os.chdir() takes the path not a command as argument.You can either use absolute or relative path
Assuming Documents is in your current directory you can do.

os.chdir("./Documents/archive")
os.getcwd()#Gives you /home/user/Documents/archive