簡體   English   中英

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不存在,此操作將失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM