text: """
      Update folder, file names, text file data and remove not needed file from dir 
  """
  
  from tkinter.filedialog import askopenfilename
  from tkinter.filedialog import askdirectory
  from tkinter  import Tk
  import stat
  import os
  import re
  
  
  Tk().withdraw()  # We don't want a full GUI, so keep the root window from appearing
  
  # FILE EXTENSIONS (Remember to update)
  #**************************************************************************
  toRemoveExtensions = [".txt", ".bat", ".dat"]  # Files to remove
  toUpdateExtensions = [".srt"]                  # Files to update content
  #**************************************************************************
  
  
  def updateFolderContents():
      path = askdirectory(title="Select Folder") # Open file explorer to select path
  
      # We don't want to process empty selection or the whole user folder or Desktop.
      if not path \
          or os.path.normpath(path) == os.path.normpath(os.path.expanduser("~/Desktop")) \
          or os.path.normpath(path) == os.path.normpath(os.path.expanduser("~")):
          print("---> Can't select this path (none selected or), this could delete important files.\n")
          return
  
      vals = valueList()
  
      if vals:
          os.chmod(path , stat.S_IWUSR)  # Give folder write permission
  
          # Update folder name.
          newFolderName = removeValuesFromName(path, vals)
          if path != newFolderName:
              os.rename(path, newFolderName)  # Rename folder
              path = newFolderName
  
          # Update files.
          for folderName, subfolders, filenames in os.walk(path):
              folderName = os.path.normpath(folderName)
              print("\nThe current folder is " + folderName)
  
              try:
                  for filename in filenames:
                      print("\t\tFILE INSIDE " + folderName + ": "+ filename)
  
                      # Remove files that are not needed and contain certain values in names.
                      if filename.endswith(tuple(toRemoveExtensions)) and fileNameContains(filename, vals):
                          os.remove(os.path.normpath(os.path.join(folderName, filename)))
                          print(f"REMOVED: {os.path.normpath(os.path.join(folderName, filename))}\n")
                      else:
                          # Update file names.
                          newFileName = removeValuesFromName(filename, vals)
                          if filename != newFileName:
                              os.rename(os.path.normpath(os.path.join(folderName, filename)), 
                                        os.path.normpath(os.path.join(folderName, newFileName)))
  
                          # Now update file content
                          fullFileName = os.path.normpath(os.path.join(folderName, newFileName))
                          if fullFileName.endswith(tuple(toUpdateExtensions)):
                              updateFileContent(fullFileName, vals)
                              
              except Exception as e:
                  print(f"\t\tERROR ({e}) skipping: {os.path.normpath(os.path.join(folderName, filename))}\n")
  
          print("\n**************************** File updating complete, now updating folders ****************************\n")
  
          # Update subfolders names.
          for folderName, subfolders, filenames in os.walk(path):
              folderName = os.path.normpath(folderName)
              try:
                  for subfolder in subfolders:
                      print("\tSUBFOLDER OF " + folderName + ": " + subfolder)
  
                      # Update subfolder names.
                      newSubfolderName = removeValuesFromName(subfolder, vals)
                      if subfolder != newSubfolderName:
                          # TODO: Will not work on root subfolders. Fix this issue, likely a race condition.
                          # os.chmod(subfolder , stat.S_IWUSR)  # Give folder write permission
                          os.rename(os.path.normpath(os.path.join(folderName, subfolder)), 
                                  os.path.normpath(os.path.join(folderName, newSubfolderName)))
              except Exception as e:
                  print(f"\tERROR ({e}) skipping: {os.path.normpath(os.path.join(folderName, subfolder))}\n")
      else:
          print("---> No file selected with values to remove.\n")
  
  
  def updateFileContent(file, dataToRemove):
      lines = None
  
      os.chmod(file , stat.S_IWUSR)  # Give file write permission
  
      # Remove lines in file that include values from list.
      with open(file, "r") as fr:
          # Reading line by line
          lines = fr.readlines()
  
      try:
          with open(file, "w") as fw:
              for line in lines:
                  for vals in dataToRemove:
                      if vals.lower() in line.lower():
                          ln = line.strip('\n')
                          line = ""
                          print(f"\t\tREMOVED: --> {ln} <-- from {file}")
                          break
  
                  fw.write(line)
  
      except Exception as e:
          with open(file, "w") as fw:
              fw.write(lines)
          print(f"\t\tERROR ({e}) can't update the contens of: {file}\n")
  
  
  def fileNameContains(fileName, values):
      for value in values:
          if value.lower() in fileName.lower():
              return True
      else:
          return False    
  
  
  def removeValuesFromName(theName, values):
      newName = theName
  
      for value in values:
          if value.lower() in newName.lower():
              # Case insensitive replace
              pattern = re.compile(re.escape(value), re.IGNORECASE)
              newName = pattern.sub("", newName)
  
  
      # TODO: Update to be a for loop with list of regex to iterate over and update string.
      # ...might also be able to just use regex to replace and merge above code with under,
      # regex values would be part of list of values from file.
      if newName.startswith("."):
          newName = newName.replace(".", "", 1)     # Remove period at the begining of strings
  
      newName = re.sub(" +", " ", newName)          # Remove multiple spaces and leave one
      newName = re.sub("\.+", ".", newName)         # Remove multiple dots and leave one
      newName = re.sub("(-.)+", ".", newName)       # Remove occurrences of these characters
      newName = newName.strip()                     # Remove whitespace from the beginning and end of a string
  
      return newName
      
  
  def valueList():
      path = askopenfilename(title="Select file")  # Open file explorer to select file
      lines = []
      
      if not path:
          return
  
      with open(path) as f:
          lines = f.read().splitlines()
  
      return lines
  
  
  if __name__ == "__main__":
      updateFolderContents()