Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
darioit
- Posts: 230
- Joined: 02 Aug 2010 05:25
#1
Post
by darioit » 22 Sep 2021 12:23
Hi everyone,
this is a small contribution for the community to thank all the time I have been helped, I hope it will be useful to someone, and I hope don't made any mistakes lol
Purpose: compare two list of elements to remove all duplicate in each list, also item remain will be used for next compare with a new file
Code: Select all
@echo off
setlocal EnableDelayedExpansion
if exist %1 type %1 >> Recycle_%1
sort.exe -u Recycle_%1 > %1 && del /q Recycle_%1
if exist %2 type %2 >> Recycle_%2
sort.exe -u Recycle_%2 > %2 && del /q Recycle_%2
for /f %%i in ("%1") do set size_%1=%%~zi
for /f %%i in ("%2") do set size_%2=%%~zi
if %size_%2% equ 0 (
type %1 > Recycle_%1
) else if %size_%1% neq 0 (
findstr /livg:%1 %2 > Recycle_%2
) else (type %1 > Recycle_%1)
if %size_%1% equ 0 (
type %2 > Recycle_%2
) else if %size_%2% neq 0 (
findstr /livg:%2 %1 > Recycle_%1
) else (type %2 > Recycle_%2)
del /q %1
del /q %2
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 22 Sep 2021 15:09
Hmm. Going to assume you want help getting this to actually work. Just looking at it I see a lot of failure points.
-
darioit
- Posts: 230
- Joined: 02 Aug 2010 05:25
#3
Post
by darioit » 22 Sep 2021 22:41
Of course I really appreciate any bug fix or improvement, I chose to use this approach because the input file or the recycle file can be empty, and using other methods the comparison always failed, and also Recycle file must be always present at the end of program
-
darioit
- Posts: 230
- Joined: 02 Aug 2010 05:25
#4
Post
by darioit » 23 Sep 2021 22:44
Where did you see "lot of failure points" ?
-
darioit
- Posts: 230
- Joined: 02 Aug 2010 05:25
#6
Post
by darioit » 24 Sep 2021 23:27
ok thank you now is better?
Code: Select all
@echo on
setlocal EnableDelayedExpansion
type nul >> "Recycle_%1"
type nul >> "Recycle_%2"
if exist "%1" type "%1" >> "Recycle_%1"
sort.exe -u "Recycle_%1" > "%1" && del /q "Recycle_%1"
if exist "%2" type "%2" >> "Recycle_%2"
sort.exe -u "Recycle_%2" > "%2" && del /q "Recycle_%2"
for /f %%i in ("%1") do set size_%1=%%~zi
for /f %%i in ("%2") do set size_%2=%%~zi
if %size_%2% equ 0 (
type "%1" > "Recycle_%1"
) else if %size_%1% neq 0 (
findstr /livg:%1 "%2" > "Recycle_%2"
) else (type "%1" > "Recycle_%1")
if %size_%1% equ 0 (
type "%2" > "Recycle_%2"
) else if %size_%2% neq 0 (
findstr /livg:%2 "%1" > "Recycle_%1"
) else (type "%2" > "Recycle_%2")
del /q "%1"
del /q "%2"