标题: 统计,当前文件及子文件(zip)内TXT文本数量(去重) [打印本页]
作者: qq110110 时间: 2019-12-11 20:58 标题: 统计,当前文件及子文件(zip)内TXT文本数量(去重)
需求描述:
统计当前文件夹及其子文件夹(zip文件)内
TXT文本(去除重复后)的数量。
1楼,能统计TXT去重个数。剩下那句话不知道加在哪。- @echo off
- title %info%
- powershell -NoProfile -ExecutionPolicy bypass "(dir -recurse|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|group {$_.Name.toLower()}).count;"
- echo;%info%
- pause
复制代码
('.zip' -eq $_.Extension)
2楼,window可以用。window7提示找不到。- <#*,:&cls
- @echo off
- pushd "%~dp0"
- Powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- Add-Type -AssemblyName System.IO.Compression.FileSystem
- # 目录列表,绝对路径或相对路径
- Get-ChildItem -Path *.txt -Recurse | Foreach-Object {
- if (!$_.PSIsContainer) {
- $_.PSChildName
- }
- } -OutVariable txtlist | Out-Null
- Get-ChildItem -Path *.zip -Recurse | ForEach-Object {
- if (!$_.PSIsContainer) {
- try {
- $archive = [System.IO.Compression.ZipFile]::Open($_.FullName, 'Read')
- $archive.Entries | ForEach-Object {
- if ($_.Name -like '*.txt') {
- $_.Name
- }
- }
- } finally {
- $archive.Dispose()
- }
- }
- } -OutVariable +txtlist | Out-Null
- $txtlist | Group-Object -OutVariable groupinfos
- "`n文本文件数量: " + $groupinfos.Count
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |