
import os
import logging


logger = logging.getLogger(__name__)


def create_directory(path):
  """
  Creates a directory if it doesn't already exist.
  """
  # Check if path is a file_path or a dir_path. Dir path is a string that
  # ends with os.sep
  if path[-1] != os.sep:
    path, file_name = os.path.split(path)

  if not os.path.exists(path):
    logger.info("Creating directory: %s", path)
    os.makedirs(path)


def get_unique_postfix(file_path, extension):
  postfix = 0
  new_path = file_path + str(postfix) + extension

  while os.path.isfile(new_path):
    postfix += 1
    new_path = file_path + str(postfix) + extension

  return new_path


def delete_directory_contents(path):
  for file_name in os.listdir(path):
    os.remove(path + os.sep + file_name)


import logging
import os
import shutil

logger = logging.getLogger(__name__)


def create_directory(path):
  """
  Creates a directory if it doesn't already exist.
  """
  # Check if path is a file_path or a dir_path. Dir path is a string that
  # ends with os.sep
  if path[-1] != os.sep:
    path, file_name = os.path.split(path)

  if not os.path.exists(path):
    logger.info("Creating directory: %s", path)
    os.makedirs(path)


def get_unique_postfix(file_path, extension):
  """Add numeric postfix for file."""
  postfix = 0
  new_path = file_path + str(postfix) + extension

  while os.path.isfile(new_path):
    postfix += 1
    new_path = file_path + str(postfix) + extension

  return new_path


def delete_directory_contents(path):
  """Remove all files and sub-dir in provided path."""
  shutil.rmtree(path)

Delete sub folders in log directory
Delete sub folders in log directory

  
+ import logging
  import os
+ import shutil
- import logging
- 
  
  logger = logging.getLogger(__name__)
  
  
  def create_directory(path):
    """
    Creates a directory if it doesn't already exist.
    """
    # Check if path is a file_path or a dir_path. Dir path is a string that
    # ends with os.sep
    if path[-1] != os.sep:
      path, file_name = os.path.split(path)
  
    if not os.path.exists(path):
      logger.info("Creating directory: %s", path)
      os.makedirs(path)
  
  
  def get_unique_postfix(file_path, extension):
+   """Add numeric postfix for file."""
    postfix = 0
    new_path = file_path + str(postfix) + extension
  
    while os.path.isfile(new_path):
      postfix += 1
      new_path = file_path + str(postfix) + extension
  
    return new_path
  
  
  def delete_directory_contents(path):
-   for file_name in os.listdir(path):
-     os.remove(path + os.sep + file_name)
+   """Remove all files and sub-dir in provided path."""
+   shutil.rmtree(path)
  
Delete sub folders in log directory
## Code Before:

import os
import logging


logger = logging.getLogger(__name__)


def create_directory(path):
  """
  Creates a directory if it doesn't already exist.
  """
  # Check if path is a file_path or a dir_path. Dir path is a string that
  # ends with os.sep
  if path[-1] != os.sep:
    path, file_name = os.path.split(path)

  if not os.path.exists(path):
    logger.info("Creating directory: %s", path)
    os.makedirs(path)


def get_unique_postfix(file_path, extension):
  postfix = 0
  new_path = file_path + str(postfix) + extension

  while os.path.isfile(new_path):
    postfix += 1
    new_path = file_path + str(postfix) + extension

  return new_path


def delete_directory_contents(path):
  for file_name in os.listdir(path):
    os.remove(path + os.sep + file_name)

## Instruction:
Delete sub folders in log directory
## Code After:

import logging
import os
import shutil

logger = logging.getLogger(__name__)


def create_directory(path):
  """
  Creates a directory if it doesn't already exist.
  """
  # Check if path is a file_path or a dir_path. Dir path is a string that
  # ends with os.sep
  if path[-1] != os.sep:
    path, file_name = os.path.split(path)

  if not os.path.exists(path):
    logger.info("Creating directory: %s", path)
    os.makedirs(path)


def get_unique_postfix(file_path, extension):
  """Add numeric postfix for file."""
  postfix = 0
  new_path = file_path + str(postfix) + extension

  while os.path.isfile(new_path):
    postfix += 1
    new_path = file_path + str(postfix) + extension

  return new_path


def delete_directory_contents(path):
  """Remove all files and sub-dir in provided path."""
  shutil.rmtree(path)
