I'm trying to copy to another directory but it's copying over there all the way (C: \ users ...), and I don't want that. I just want to copy the current folder and its subdirectories. I also want to leave a symbolic link when the file is moved. I got this script here on the site, it's a great script! Thank you all for your attention The script is this:
$sourceDir = "C:\Users\295078898\Documents\Teste"
$archiveTarget = "C:\Users\295078898\Downloads\Teste"
$dateToday = Get-Date
$date = $dateToday.AddDays(-20)
$items = Get-ChildItem $sourceDir -recurse |
Where-Object {!$_.PSIsContainer -and $_.LastWriteTime -le $date}
foreach ($item in $items) {
$withoutRoot = $item.FullName.Substring([System.IO.Path]::GetPathRoot($item.FullName).Length);
$destination = Join-Path -Path $archiveTarget -ChildPath $withoutRoot
$dir = Split-Path $destination
if (!(Test-Path $dir)) {
mkdir $dir
}
Move-Item -Path $item.FullName -Destination $destination
function CreateLink {
param (
[string] $LinkName,
[string] $TargetFile
)
&"cmd.exe" /c mklink "$LinkName" "$TargetFile" | Out-Null
}
CreateLink -LinkName $item.FullName -TargetFile $destination
}