找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 13577|回复: 1

【完结】删除文件+50元

  [复制链接]
发表于 2021-10-4 09:11:25 | 显示全部楼层 |阅读模式
本帖最后由 lxh623 于 2021-10-4 10:20 编辑

文件夹“epub解包”下面有多个同级文件夹,每一个文件夹有子文件夹text和images。前者含有多个html,后者含有jpeg。
html中的代码,包括如下:
src="../images/00222.jpeg
想汇总html所有的jpeg,然后,把images中多余的jpeg删除。

每一个文件夹独立处理。

谢谢!
发表于 2021-10-4 09:59:57 | 显示全部楼层
本帖最后由 went 于 2021-10-4 10:05 编辑

保存bat文件
  1. @cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" &pause&exit
  2. Get-ChildItem 'epub解包\*' | Where-Object {[System.IO.Directory]::Exists($_.FullName)} | foreach {
  3.     $_.FullName
  4.     $f1 = $_.FullName + '\text'
  5.     $f2 = $_.FullName + '\images'
  6.     if([System.IO.Directory]::Exists($f1) -and [System.IO.Directory]::Exists($f2)){
  7.         $images1 = &{
  8.             Get-ChildItem ($f1 + '\*.html') | foreach {
  9.                 Get-Content $_.FullName | foreach {
  10.                     if($_ -match 'src="../images/(.*?.jpeg)'){
  11.                         $Matches[1]
  12.                     }
  13.                 }
  14.             }
  15.         } | Select-Object -Unique
  16.         Get-ChildItem ($f2 + '\*.jpeg') | Where-Object { $images1 -notcontains $_.Name } | foreach {
  17.             '删除: ' + $_.FullName
  18.             Remove-Item $_
  19.         }
  20.     }
  21.     '---------------------------'
  22. }
复制代码

评分

参与人数 1技术 +1 收起 理由
lxh623 + 1 乐于助人

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:35 , Processed in 0.017711 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表