Reputation: 1195
Ok so this is driving me nuts but i'll try explain myself as well as I can :)
I have a folder of duplicates and non duplicates like below
1.txt
1.txt
1.txt
2.txt
2.txt
3.txt
3.txt
4.txt
4.txt
4.txt
4.txt
5.txt
6.txt
7.txt
7.txt
7.txt
7.txt
8.txt
Now I want to find only the duplicates of files that are more than 3, In this case that would be all the 7.txt
and 4.txt
files. BUT the files go on to infinity.txt
So there is no way i can pre-set the conditions. the script must recognize that there is more than 3 duplicates so i can extract those files.
--- Alright so i tried the script below which works well however it does not "extract" as mentioned above.
Here is a link to a question I asked concerning this but I battled to explain it well enough.
`@echo off
setlocal EnableDelayedExpansion
for %%a in (*.eml) do (
for /F "tokens=3 delims=_" %%b in ("%%~Na") do (
set "fileTime=%%b"
for %%t in (!fileTime:~0^,4!) do (
set /A "count[%%t]+=1"
set names[%%t]=!names[%%t]! "%%a"
)
)
)
for /F "tokens=2,3 delims=[]=" %%a in ('set count[') do (
if %%b gtr 1 (
for %%c in (!names[%%a]!) do (
type "%%~c" >> C:\output\%%~ci.eml
)
)
)`
Upvotes: 2
Views: 48
Reputation: 1195
@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR %%a in (*.eml) DO (
FOR /F "tokens=3 delims=_" %%b IN ("%%~Na") DO (
SET "fileTime=%%b"
FOR %%t in (!fileTime:~0^,4!) DO (
SET /A "count[%%t]+=1"
SET names[%%t]=!names[%%t]! "%%a"
)
)
)
FOR /F "tokens=2,3,4 delims=[]=" %%a IN ('set count[') DO (
IF %%b gtr 3 (
FOR %%c IN (!names[%%a]!) DO (
TYPE "%%~c" >> C:\output\%%~ci.eml
)
)
)
I missed a token... thanks for the help guys. so the script is working now. It sends .eml
files with more than 3 of the same prefixes to the output
folder.
Upvotes: 2