os.unlink(path)
path -- 這是被刪除路徑
# !/usr/bin/python3 import os, sys os.chdir("d:\\tmp") # listing directories print ("The dir is: %s" %os.listdir(os.getcwd())) os.unlink("foo.txt") # listing directories after removing path print ("The dir after removal of path : %s" %os.listdir(os.getcwd()))
The dir is: ['Applicationdocs.docx', 'book.zip', 'foo.txt', 'Java Multiple Inheritance.html', 'Java Multiple Inheritance_files', 'java.ppt', 'python2'] The dir after removal of path : ['Applicationdocs.docx', 'book.zip', 'Java Multiple Inheritance.html', 'Java Multiple Inheritance_files', 'java.ppt', 'python2']