Python Tutorial

Friday, August 20, 2010

python remove/delete file

'''
   This code use for remove a file
'''
import os
import sys

directory="C:/pythonInputFile.doc"
if os.path.exists(directory):
    try:
        os.remove(directory)
    except:
        print "Exception: ",str(sys.exc_info())
else:
    print 'File not found at ',directory




Output:
Check current directory

0 comments:

Post a Comment