os.chdir()
os.chdir() method in Python used to change the current working directory to a specified path. It takes only a single argument as a new directory path.
Python3
# Python3 program to change the # directory of file using os.chdir() method # import os library import os # change the current directory # to specified directory os.chdir(r "C:\Users\Gfg\Desktop\geeks" ) print ( "Directory changed" ) |
Output:
Directory changed
10 Python File System Methods You Should Know
While programming in any language, interaction between the programs and the operating system (Windows, Linux, macOS) can become important at some point in any developer’s life. This interaction may include moving files from one location to another, creating a new file, deleting a file, etc.