''' This code use for remove a file/folder ''' import os import sys import shutil def deleteFileOrFolder(directory): if os.path.exists(directory): try: if os.path.isdir(directory): # delete folder shutil.rmtree(directory) else: # delete file os.remove(directory) except: print "Ecxeption ",str(sys.exc_info()) else: print "not found ",directory ''' Function call ''' #directory="C:/pythonFile.txt" directory="C:/inputFolder/" directory=deleteFileOrFolder(directory)
Output:
Check current directory
0 comments:
Post a Comment