I realise this question seems to have been asked a thousand times before, and I've read most if not all the suggestions (most common being new ps-drive or using alphaFS). I just never see that suggestion actually put into code.
My program works fine the way I've coded it for now, with 1 exception being the too long path exception i run into once in a while. While i start from a path that is not too long, i will recursively pass down the path length to find all files with a specific extension and move it around. I'm just wondering how i can test get-childitem and start making a new temp ps drive without having the exception already.
the code: (part of it)
Get-ChildItem -Path $loc -File -Filter $extension -Recurse |
Where-Object { $_.FullName -inotmatch $folder_name } |
ForEach-Object {
if((Test-Path (Join-Path $Destination $_)) -eq $true) {
$tmp_name = "$($_.BaseName)$(Get-Date -Format "dd_MM_yyyy_hh_mm_ss")$($_.Extension)"
Rename-Item $_.FullName $tmp_name
Move-Item ((Split-Path -Path $_.FullName)+"\"+$tmp_name) -Destination $Destination -Verbose 4>>$Destination\$filename -Force;
}
else{$_ | Move-Item -Destination $Destination -Verbose >>$Destination\$filename -Force
}
}
This basically test if the file exists at the location I want to move it to, and if so will rename with current time in the name.
Now I want to implement the new ps-drive if the get-childitem path gets at 200 length. But according to me you can't filter before querying the path length and already run into the exception.
Or am I wrong?