ok, look at the
bold bits - I've left in the original code, commented out with '#'.. NB, all untested, just off the top of my head
#decide how long back to go
#$timespan = new-timespan -days 7
$timespan = new-timespan -days 90
#move the files to a temporary location
foreach($file in $files)
{
#$fileLastModifieddate = $file.LastWriteTime
$filenameFromPath = [System.IO.Path]::GetFileName($file)
$dateFromFilename = $filenameFromPath.Substring(4,8)
$fileCreateDate = [datetime]::parseexact($dateFromFilename, 'yyyyMMdd', $null)
#if(((Get-Date) - $fileLastModifiedDate) -gt $timespan)
if(((Get-Date) - $fileCreateDate) -gt $timespan)
{
The '#' code etc can be removed when it's working, and those sequences of mine can be combined to some extent, but it makes it easier to show the why && what if I express them long-form first