DEV Community

PyBash
PyBash

Posted on • Originally published at pybash.hashnode.dev on

Quick Post: How to go up/down a directory structure using Python!

Introduction

Introducing Quick Posts - Small posts containing useful tips and tricks! This is a series! These posts will not have a Subtitle or Cover photo

Content

So suppose, you're in a directory C:\Windows\system32 and want to go to C:\Windows, so how do you do that? Well, you can use os.chdir(), yeah! But how? Code below:

import os

print(os.getcwd())
os.chdir("..")
print("\n", os.getcwd())

Enter fullscreen mode Exit fullscreen mode

Output Below:

C:\Windows\system32> python quick-post-1.py
C:\Windows\system32

C:\Windows

Enter fullscreen mode Exit fullscreen mode

End

Thanks, for reading Quick Posts! More coming soooooooon! Stay Alert!

Oldest comments (0)