[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

需求描述:

统计当前文件夹及其子文件夹(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
复制代码

返回列表