[Base] python os module (library) method summary

  1, rename

1 os.rename ()    # can only change the name of the current file 
2 os.renames ()    # can change the parent directory if parent directory does not exist, create

  2, delete the file

1 os.remove ()    # to delete the specified path of the file, if the specified path is a directory, an error

  3, create a directory

1 os.mkdir ()    # Create a directory, if the directory already exists, it will error 
2  # can only be used to create a directory, create multi-level directory error will be 
3 os.makdirs ()    # can create multi-level directory, if the directory already exists, it will error 
4  # If exist_ok = True, the directory already exists, the error will not

  4, delete the directory

1 os.rmdir ()   # delete a directory, if the directory does not exist, an error 
2 os.removedirs ()    # delete multi-level directory, if the directory is empty, then removed until a directory is not empty so far

  5, to get the current directory

1 os.getcwd()

  6, get a directory listing

1 os.listdir ()

  7, switching directory

1 os.chdir()

  8, to determine whether a file exists

1 os.path.exists()

  9, to determine whether the files, directories

1 os.path.isfile()
2 os.path.isdir()

  10, to determine whether the absolute path

1 os.path.abs()

  11, get the last part (file name) path

1 os.path.basename()

  12, access path portion of the path (the path in front of all file names)

1 os.path.dirname()

Guess you like

Origin www.cnblogs.com/Tree0108/p/12116488.html