![](/img/trans.png)
[英]Powershell copying specific files from all subfolders to a single folder
[英]Copying files and it's subfolders
我正在尝试复制到另一个目录,但它一直复制到那里(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
}
尝试这样的事情:
$sourceDir = [string]"C:\TMP\295078898\Teste"
$archiveTarget = [string]"C:\Temp\295078898\Teste"
$dateToday = Get-Date
$date = $dateToday.AddDays(-20)
$items = Get-ChildItem $sourceDir -recurse |
Where-Object {!$_.PSIsContainer -and $_.LastWriteTime -le $date}
foreach ($item in $items) {
Move-Item -Path $item.FullName -Destination $archiveTarget
New-Item -ItemType SymbolicLink -Target $archiveTarget -Path $item.FullName -Force
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.