-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
  • 4,543
  • 5
  • 22
  • 49
Jhonatan Zu
  • 169
  • 1
  • 3
  • 12

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