title: Delete old files after X days by default with exception on certain dirs [Powershell]
body: <p>I'm trying to fix the following scenario:</p>
  
  <p>I have directory which has multiple subdirectories and files where I need to set something like retention policy, by default I would set to have files no older than 365 days where there are some special directories where I would like to keep for a different period of time other than my default value. These directories are specified in a txt file with the following syntax</p>
  
  <p>Content of Drive:\Path\to\special_dirs.txt</p>
  
  <pre><code>D:\Path\to\vendor1 -396
  D:\Path\to\vendor2 -45
  </code></pre>
  
  <p>This is what I have come up so far (It is working on the special directories only, the next part where I want to proceed with the rest does not work):</p>
  
  <pre><code># Script to remove old files from Archive: D:\Path\to
  # Declaring variables to be used
  $controlfile = "Drive:\Path\to\list\special_dirs.txt"
  $dir = "D:\Path\to"
  $default_days = "-365"
  $excluded_dirs = Get-Content $controlfile | Foreach-Object {$_.Split()[0]}
  
  foreach ($line in Get-Content $controlfile) {
      $split = $line.split(" ")
      $file_path = $split[0]
      $max_days = $split[1]
  
      Get-ChildItem $file_path -Include *.* -File -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays($max_days))} | Remove-Item -Force -Recurse -Verbose -WhatIf
  }
  
  # Removing everything else older than 365 days old
  Get-ChildItem -Path $dir -Include *.* -File -Recurse -Directory -Exclude $excluded_dirs | Where-Object {($_.LastWriteTime -lt $curr_date.AddDays($default_days))} | Remove-Item -Force -Recurse -Verbose -WhatIf
  </code></pre>
  
  <p>I'm not looking to remove directories even if they are empty, I just want to remove files, the last part of the script just deletes everything older than 365 day where there is a directory that I would like to keep 30 days more than the default period of time, any ideas on how to get this done?
  I used the file list so that I can keep adding directories to vendors where I can keep longer than or even less than the default days.</p>