我已经挣扎了一段时间了,希望有人可以帮助我。
我有一堆 *.pdf 文件,其中文件名还包含文件应该移动到的文件夹的名称。我发现的代码运行良好:
$Folder = "C:\Users\Bob\Desktop\Scripting\Bronmap"
$FileType = "*.pdf"
$Files = Get-ChildItem -Path $Folder -Filter $FileType
$RE = [regex]((Get-ChildItem -Path $Folder -Directory -Name) -Join '|')
ForEach($file in $Files){
if ($file.BaseName -Match $RE){
$file | Move-Item -Destination (Join-Path $Folder $Matches[0] )
}
else {
$file | Move-Item -Destination (Join-Path $Folder "No_Folder")
}
}
我想要的是将文件移动到命名文件夹中的子文件夹中,并具有特定名称“合同”。例如:
$file | Move-Item -Destination (Join-Path $Folder $Matches[0] "Contracts" )
虽然子文件夹存在,但我无法让它工作。任何帮助都受到高度赞赏。
Join-Path
有两个参数,$Folders
并$Matches[0]
在你的情况,所以"Contracts"
不应该在那里。
您可以使用Join-Path
两次:
(Join-Path (Join-Path $Folder $Matches[0]) "Contracts")
或手动连接合同:
(Join-Path $Folder ($Matches[0] + "\Contracts"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句