os.remove(path)
path -- 這是將被刪除的路徑
# !/usr/bin/python3 import os, sys os.chdir("d:\\tmp") # listing directories print ("The dir is: %s" %os.listdir(os.getcwd())) # removing os.remove("test.java") # 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', 'home', 'Java Multiple Inheritance.html', 'Java Multiple Inheritance_files', 'java.ppt', 'ParallelPortViewer', 'test.java'] The dir after removal of path : ['Applicationdocs.docx', 'book.zip', 'foo.txt', 'home', 'Java Multiple Inheritance.html', 'Java Multiple Inheritance_files', 'java.ppt', 'ParallelPortViewer']