Delete directories and files

Delete empty directories

os Import 
Import SYS 
path = sys.argv [1] 
the try: 
    IF os.path.exists (path): 
        os.rmdir (path) 
        Print ( "deleted successfully") 
    the else: 
        Print ( "directory does not exist") 
the except OSError: 
    print ( "directory not empty")

Delete the directory and its subdirectories and contents

shutil Import 
Import os 
Import SYS 
path = sys.argv [1] 
IF os.path.exists (path): 
    shutil.rmtree (path) 
    Print ( "deleted successfully") 
the else: 
    Print ( "directory does not exist")

  

Guess you like

Origin www.cnblogs.com/wlinuxtop/p/11795590.html