text: #!/usr/bin/env python
  # coding: utf-8
  
  # John Deere Boundary Export from Operations Center into TopCon Folder Structure
  
  # Export Active Boundaries from operations center as individual shapefiles (online)
  # Extract boundaries.zip to target location (online)
  
  # Create Initial Folder Structure from file names in boundaries file 
  # Create a list of all unique file names in boundaries folder (ignore extension)
  # For each item in the list, create a folder under Client / Farm (user selected Farm)
  # Copy the shapefile files into this new folder
  # Optionally delete original files
  
  # Use tk to ask user to select boundaries folder.
  import os
  from tkinter import Tk
  from tkinter import filedialog
  import shutil
  
  # Hides the tk prompt thing.
  root = Tk()
  root.withdraw()
  
  current_dir = filedialog.askdirectory(title='Select boundaries folder')
  
  # Make Output folder + top level client (one folder up from selected)
  output_folder = "../Output/Clients"
  output_path = os.path.join(current_dir, output_folder)
  os.makedirs(output_path, exist_ok=True)
  
  # create list of files in boundaries folder.
  file_list = os.listdir(current_dir)
  
  # Output Path becomes the new target directory
  
  # build folder structure
  
  for file in file_list:
      # remove the extension
      file_ext = file.split('.', 1)
      # create variable for the first part of the file
      file_full_name = file_ext[0]
      # split the file into 3 components
      file_split = file_full_name.split('_')
  
      # Build new file names for copying (+ can check if i need to copy it)
      ext = file_ext[1]
      nam = file_split[2]
      new_name = nam + "." + ext
  
      # additional Folders for Boundaries and AbLines.
      bounds = "boundaries"
      lines = "AbLines"
  
      if ext == 'shp' or ext == 'dbf' or ext == 'shx':
  
          # turn the split file into a directory
          # Index error expected if encountering folders in the file structure. (should be fixed by relocating the Output Folder) 
          try:
              file_dir = os.path.join(output_path, file_split[0], file_split[1], file_split[2], bounds)
          except IndexError:
              pass
  
          # probably the wrong way to go about this...
          try:
              file_dir2 = os.path.join(output_path, file_split[0], file_split[1], file_split[2], lines)
          except IndexError:
              pass
  
          # Build Folder directory with makedirs()  
          os.makedirs(file_dir, exist_ok=True)
          os.makedirs(file_dir2, exist_ok=True)
          # Copy file to new destination
  
          # Combine the original directory with the file name as the source
          src_file = os.path.join(current_dir, file)
          # Combine the new directory with a shortened version of the name as the desination
          dest_file = os.path.join(file_dir, new_name)
          # Copy files to the Output location
          shutil.copyfile(src_file, dest_file)
  
  
  