Python OS Module

The os module is a built-in module in Python that provides a way to interact with the operating system. It contains functions for interacting with the file system, process management, environment variables, and other system-specific functionalities.

Here are some of the main functions provided by the os module:

  1. os.getcwd() – Returns the current working directory of the process.
  2. os.chdir(path) – Changes the current working directory to the specified path.
  3. os.listdir(path='.') – Returns a list of files and directories in the specified directory.
  4. os.mkdir(path) – Creates a new directory at the specified path.
  5. os.rmdir(path) – Removes the directory at the specified path (only works if the directory is empty).
  6. os.rename(src, dst) – Renames a file or directory from the source path to the destination path.
  7. os.remove(path) – Deletes the file at the specified path.
  8. os.path.join(path1[, path2[, ...]]) – Joins two or more path components together.
  9. os.path.abspath(path) – Returns the absolute path of the specified path.
  10. os.path.exists(path) – Returns True if the specified path exists, False otherwise.
  11. os.path.isfile(path) – Returns True if the specified path is a file, False otherwise.
  12. os.path.isdir(path) – Returns True if the specified path is a directory, False otherwise.
  13. os.environ – A dictionary-like object containing the environment variables.
  14. os.system(command) – Executes the specified command in a subshell.

These are just a few examples of the functions provided by the os module. The module is quite powerful and allows you to perform many different types of operations on the operating system from within Python.