【发布时间】:2023-03-17 12:45:01
【问题描述】:
我已经苦苦挣扎了一段时间,希望有人能帮助我。
我有一堆 *.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" )
虽然子文件夹存在,但我无法让它工作。 非常感谢任何帮助。
【问题讨论】:
标签: powershell path filenames move