我正在尝试复制到另一个目录,但它一直复制到那里(C:\ users ...),我不希望那样。我只想复制当前文件夹及其子目录。我还想在移动文件时留下一个符号链接。我在网站上找到了这个脚本,这是一个很棒的脚本!谢谢大家的关注脚本是这样的:
$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
}