- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
-
- Get-ChildItem | Where-Object { $_.PSIsContainer } | ForEach-Object {
- $datafile = Join-Path -Path $_.FullName -ChildPath "DATA_$($_.Name).txt"
- $jpgs = @($_ | Get-ChildItem | Where-Object { $_.Extension -eq '.jpg' } | Select-Object -Property @{
- Name = 'jpgName'
- Expression = { $_.Name }
- }, @{
- Name = 'FullName'
- Expression = { $_.FullName }
- })
- $lines = Get-Content -ReadCount 0 -LiteralPath $datafile
- $header = $lines[0]
- $linesdata = @($lines | Select-Object -Property @{
- Name = 'jpgName'
- Expression = {
- if ($_ -match '\|([^|]*)$') {
- $Matches[1]
- }
- }
- }, @{
- Name = 'line'
- Expression = { $_ }
- } -Skip 1)
- $comp = Compare-Object -ReferenceObject $linesdata -DifferenceObject $jpgs -Property jpgName -IncludeEqual -PassThru
- $(
- $header
- foreach ($item in $comp) {
- if ($item.SideIndicator -eq '==') {
- # 匹配与jpg相同的行
- $item.line
- } elseif ($item.SideIndicator -eq '=>') {
- # 删除多余的jpg
- Remove-Item -LiteralPath (Join-Path -Path $_.FullName -ChildPath $item.jpgName) -Verbose
- }
- }) | Set-Content -LiteralPath $datafile
- }
复制代码 脚本放到2022文件夹下, 保存为ANSI编码; 先找测试目录,以免删除文件错误. |