I have to delete files older then x
days so, knowing that we use paths longer than 260 characters, I wrote the following as a workaround:
$path= "\\very.long.path\Files\P\still\_veryLong\more_stuff\never_finish\Local\Development\really_longher_tha_260"
if (-not (Test-Path TEMP:)) {
echo "Mounting virtual drive TEMP: ..."
New-PSDrive -Name TEMP -PSProvider FileSystem -Root $path
}
Now, the problem is that even in this way, when I perform a search I've got the following:
Get-ChildItem TEMP: -Recurse -Force | Where-Object {
!$_.PSIsContainer -and $_.CreationTime -lt $limit
}
Get-ChildItem : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters At C:\UserTemp\WorkStuff\jkCleanOldFiles.ps1:19 char:13 + $allFiles = Get-ChildItem . -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError: (\\very.long.path\Files..lpha-9-stable- :String) + Get-ChildItem], PathTooLongException + FullyQualifiedErrorId : irIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
From this line:
+ CategoryInfo : ReadError: (\\very.long.path\Files...lpha-9-stable- :String)
It looks like the path it's still starting at "\very.long.path\Files" while I would expect for it to start at "TEMP:\".
Can someone help? What am I missing?
EDIT: fixed using subst instead of New-PSDrive