title: pyspark - how to delete a local directory if it already exists
body: <p>i wish to delete a local directory if it already exists. below is my code:</p>
  
  <pre><code>import sys
  import os
  from pyspark import SparkContext
  from pyspark import SparkConf
  
  conf=SparkConf().setAppName('pyspark')
  sc=SparkContext(conf=conf)
  
  data=sc.textFile('file:///home/cloudera/Downloads/SAN_SALES_EXTRACT_TRANS_LEVEL_D0906.txt')
  datamap=data.map(lambda x: ((str(x.split(',')[1]).strip(),int(x.split(",")[0])),float(x.split(",")[10])))
  datagrouped=datamap.reduceByKey(lambda x,y: x+y)
  if (os.path.exists("file:///home/cloudera/Downloads/store_perday_rev")):
          os.remove("file:///home/cloudera/Downloads/store_perday_rev")
  else:
          datagrouped.sortByKey().saveAsTextFile("file:///home/cloudera/Downloads/store_perday_rev")
  #for i in datagrouped.sortByKey().take(20):
  #       print(i)
  </code></pre>
  
  <p>It doesn't delete the directory. What am i doing wrong?</p>