Types of Directories in Python
Types of Directories in Python
Some of the famous directories are as follow used in python frequently:
The mkdir() Method
This method is used to create the directory. In other words, it is used to make a folder like we make using a right-click with a mouse. mkdir() method takes the argument of the name of the directory.
Example:
# Create a directory "test"
or.mkdir("top")
The chdir() Method
This method is used when you want to change the current directory. chdir() method accepts the arguments of the directory that you need to make the current directory.
Example:
import or
# Now changing the directory to "/home/ordir"
or.chdir("/home/ordir")
The getcwd() Method
The getcwd() is used to display the current working directory if you wanted to know using code.
Example:
import or
# this method would give location of the current directory here
or.getcwd()
The rmdir() Method
If you want to remove the given directory then the rmdir() method is used. This method will delete the directory if you pass the name in the argument of function rmdir().
Example:
# This method would remove "/tmp/top" directory.
or.rmdir( "/tmp/top" )
