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

统计,当前文件及子文件(zip)内TXT文本数量(去重)

  [复制链接]
发表于 2019-12-11 20:58:26 | 显示全部楼层 |阅读模式
需求描述:

统计当前文件夹及其子文件夹(zip文件)内
TXT文本(去除重复后)的数量。         

1楼,能统计TXT去重个数。剩下那句话不知道加在哪。
  1. @echo off
  2.     title %info%
  3.     powershell -NoProfile -ExecutionPolicy bypass "(dir -recurse|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|group {$_.Name.toLower()}).count;"
  4.     echo;%info%
  5.     pause
复制代码
('.zip' -eq $_.Extension)
2楼,window可以用。window7提示找不到。
  1. <#*,:&cls
  2.     @echo off
  3.     pushd "%~dp0"
  4.     Powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath "%~0" -ReadCount 0 | Out-String ))) "
  5.     popd
  6.     pause
  7.     exit /b
  8.     #>
  9.     Add-Type -AssemblyName System.IO.Compression.FileSystem
  10.     # 目录列表,绝对路径或相对路径
  11.     Get-ChildItem -Path *.txt -Recurse | Foreach-Object {
  12.       if (!$_.PSIsContainer) {
  13.         $_.PSChildName
  14.       }
  15.     } -OutVariable txtlist | Out-Null
  16.     Get-ChildItem -Path *.zip -Recurse | ForEach-Object {
  17.       if (!$_.PSIsContainer) {
  18.         try {
  19.           $archive = [System.IO.Compression.ZipFile]::Open($_.FullName, 'Read')
  20.           $archive.Entries | ForEach-Object {
  21.             if ($_.Name -like '*.txt') {
  22.               $_.Name
  23.             }
  24.           }
  25.         } finally {
  26.           $archive.Dispose()
  27.         }
  28.       }
  29.     } -OutVariable +txtlist | Out-Null
  30.     $txtlist | Group-Object -OutVariable groupinfos
  31.     "`n文本文件数量: " + $groupinfos.Count
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 06:49 , Processed in 0.016560 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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