DEV Community

loading...

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

PyBash
I am a developer from India. I use Python to develop my software/tools. I make software/tools - ranging from mini CLI-full GUI. I think these tools help in making life easier. Love Web dev. as well.
Originally published at pybash.hashnode.dev on ・1 min read

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!

Discussion (0)