SHARE
TWEET

# b_deleteDir.py

here2share May 25th, 2020 910 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # b_deleteDir.py
  2.  
  3. f = r'E:\filename'
  4.  
  5. import sys
  6. import os
  7.  
  8. mswindows = (sys.platform == "win32")
  9.  
  10. def getstatusoutput(cmd):
  11.     """Return (status, output) of executing cmd in a shell."""
  12.     if not mswindows:
  13.         return commands.getstatusoutput(cmd)
  14.     pipe = os.popen(cmd + ' 2>&1', 'r')
  15.     text = pipe.read()
  16.     sts = pipe.close()
  17.     if sts is None: sts = 0
  18.     if text[-1:] == '\n': text = text[:-1]
  19.     return sts, text
  20.  
  21.  
  22. def deleteDir(path):
  23.     """deletes the path entirely"""
  24.     if mswindows:
  25.         cmd = "RMDIR "+ path +" /s /q"
  26.     else:
  27.         cmd = "rm -rf "+path
  28.     result = getstatusoutput(cmd)
  29.     print result[1]
  30.     print result[0]
  31.     if(result[0]!=0):
  32.         raise RuntimeError(result[1])
  33. 0
  34. deleteDir(f)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top