Os.remove (PATH)
Deletes the file path. If path is a directory, throw a oserror error. If you want to delete a directory, use RmDir ().
The Remove () function is the same as unlink ()
In a Windows system, deleting a file that is in use throws an exception. In Unix, records in a catalog table are deleted, but the files are stored.
Os.removedirs (PATH)
Deletes a directory recursively. Similar to RmDir (), if a subdirectory is successfully deleted, Removedirs () deletes the parent directory, but the subdirectory is not successfully deleted, and an error is thrown.
For example, Os.removedirs ("Foo/bar/baz") will first delete the "Foo/bar/ba" directory and then remove Foo/bar and foo if they are empty
If the subdirectory cannot be successfully deleted, the OSError exception is thrown
Os.rmdir (PATH)
Delete directory path, request path must be an empty directory, or throw OSError error
Recursively delete directories and files (similar to DOS command DeleteTree):
Import OS
For Root, dirs, the files in Os.walk (top, Topdown=false):
For name in Files:
Os.remove (Os.path.join (root, name))
For name in dirs:
Os.rmdir (Os.path.join (root, name))
Method 2: Masarica, Horong
Import Shutil
Shutil.rmtree ()
One line to fix __import__ (' Shutil '). Rmtree ()