jmquintana79
4/21/2016 - 5:44 AM

os filesystem from Python

Os filesystem magament from Python

"""
Launch bash command

input:
-sbashCommand[str]: command to be executed
output[str]: confirmation or output
"""
def launch(sbashCommand):
    import subprocess
    try:
        return subprocess.check_output(['bash','-c', sbashCommand])
    except Exception as e:
        print(str(e))
        return None
       

"""
Create folder if not exists

input:
-folder[str]: folder to be created
"""
def mkdiros(folder):
  import os
  if not os.path.exists(folder):
      os.makedirs(folder)
    

def mkdiros(folder):
  from pathlib import Path
  path = Path(folder)
  path.mkdir(parents=True, exist_ok=True)
  
  
"""
Delete file/folder if exits

input: 
-path[str]:path to be deleted
"""
def delos(path):    
  import os
  try:
      os.remove(path)
  except OSError:
      pass