Powershell - 将文件移动到更深的 1 个文件夹
Powershell - Move files 1 folder deeper
我想将一大组 pdf 文件移到更深的文件夹中。
当前文件结构为:
[Reference Code]\[file].pdf
我希望将文件移动到:
[Reference Code]\April 18\[file].pdf
如果我没记错的话,这可以在 linux 中用 mv */*.pdf */April 18/*.pdf
完成,但是 windows 的解决方案似乎有点复杂
$rootPath = "C:\"
$moveTo = "C:\April 18"
foreach ($pdfFile in (Get-ChildItem $rootPath | Where-Object {$_.Extension -eq ".pdf"}))
{
Move-Item -Path $pdfFile.FullName -Destination "$moveTo$($pdfFile.Name)"
}
像这样?
一种可能:
$rootDir = "Reference Code"
Get-ChildItem -Path "$rootDir\*.pdf" -File |
ForEach-Object {
Move-Item $_.FullName -Destination "$rootDir\April 18$($_.Name)"
}
请注意,如果文件夹 April 18
不存在,这将失败。
我想将一大组 pdf 文件移到更深的文件夹中。
当前文件结构为:
[Reference Code]\[file].pdf
我希望将文件移动到:
[Reference Code]\April 18\[file].pdf
如果我没记错的话,这可以在 linux 中用 mv */*.pdf */April 18/*.pdf
完成,但是 windows 的解决方案似乎有点复杂
$rootPath = "C:\"
$moveTo = "C:\April 18"
foreach ($pdfFile in (Get-ChildItem $rootPath | Where-Object {$_.Extension -eq ".pdf"}))
{
Move-Item -Path $pdfFile.FullName -Destination "$moveTo$($pdfFile.Name)"
}
像这样?
一种可能:
$rootDir = "Reference Code"
Get-ChildItem -Path "$rootDir\*.pdf" -File |
ForEach-Object {
Move-Item $_.FullName -Destination "$rootDir\April 18$($_.Name)"
}
请注意,如果文件夹 April 18
不存在,这将失败。