以下是PowerShell脚本:
$sourceFolder = "C:\Users\user\Desktop\source" $destinationFolder = "C:\Users\user\Desktop\destination"
$jpgFiles = Get-ChildItem $sourceFolder -Filter *.jpg
foreach ($jpgFile in $jpgFiles) {
$fileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($jpgFile.Name) $subfolderPath = Join-Path $destinationFolder $fileNameWithoutExtension New-Item -ItemType "directory" -Path $subfolderPath | Out-Null
$destinationPath = Join-Path $subfolderPath $jpgFile.Name Copy-Item $jpgFile.FullName $destinationPath }
在脚本中,您需要将源文件夹和目标文件夹的路径替换为您自己的路径。该脚本还依赖于“Get-ChildItem”和“Copy-Item”Cmdlet,这些Cmdlet能够获取文件并将文件复制到指定位置。最后,在循环期间,使用“New-Item”Cmdlet创建子文件夹。
上一篇:编写PowerShell脚本导出SharePoint站点超过90天未活动的信息
下一篇:编写PowerShell脚本来搜索所有组织单位中的'Servers”对象并将其移动到'Servers”组织单位中。