复制文件及其子文件夹

问题描述 投票:0回答:1

我正在尝试复制到另一个目录,但是它一直都在那儿复制(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 
}
windows powershell powershell-4.0 cmdlets movefile
1个回答
0
投票

尝试这样的事情:

    $sourceDir = [string]"C:\TMP\295078898\Teste"
    $archiveTarget = [string]"C:\Temp\295078898\Teste"

    Move-Item -Path $sourceDir -Destination $archiveTarget

    New-Item -ItemType SymbolicLink -Target $sourceDir -Path $archiveTarget -Force
© www.soinside.com 2019 - 2024. All rights reserved.