Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


Guest

Code to find files not in a list

14 posts in this topic

I'm looking to do the opposite of this....

FOR %%i IN (
WindowsXP-KB2756822-x86-ENU.exe
WindowsXP-KB2761226-x86-ENU.exe
WindowsXP-KB2761465-x86-ENU.exe
WindowsXP-KB2778344-x86-ENU.exe
WindowsXP-KB2779030-x86-ENU.exe
WindowsXP-KB2792100-x86-ENU.exe
WindowsXP-KB2797052-x86-ENU.exe
WindowsXP-KB2799329-x86-ENU.exe
WindowsXP-KB2799494-x86-ENU.exe
WindowsXP-KB2808735-x86-ENU.exe
WindowsXP-KB2809289-x86-ENU.exe
WindowsXP-KB2817183-x86-ENU.exe
) DO (IF EXIST %%i echo %%i exists)

In other words, if there are some files that are not in the list, output something like echo %%i is and unknown file. Ask yourself why you need this.

I suppose the only way to do this is with a dir /b>updates.txt or using OR's?

Thanks!

0

Share this post


Link to post
Share on other sites

Thanks but it's for my UDC script and I can't redistribute MS binaries. I looked at the page and still don't see a way to do it with it.

0

Share this post


Link to post
Share on other sites

Why not use "findstr /V" as it will show everything except the pattern ?

0

Share this post


Link to post
Share on other sites

To be clear... The purpose is to notify/move any/all items NOT in your "standard download/build" list? I say that because I noted some IE7 Updates (among others) in your UDC script. You wish to "generically" eliminate any/all "OTHER" files? :unsure:

I noted a tendency of some users of your Script to "include" stuff that should NEVER have been there and then wondered "gee, why did it fail?"... (still :unsure:)

0

Share this post


Link to post
Share on other sites

Are you trying to exclude certain updates from being installed?

0

Share this post


Link to post
Share on other sites

To notify them that they are there and ask them to investigate further. I wont move them because of other add-ons they may add but way too many times they include crap updates. All they need are my updates.

0

Share this post


Link to post
Share on other sites

I like recursive batch files:


@echo off
if %1*==* goto NOPARAM

::Only list unapproved updates
if %1==WindowsXP-KB2756822-x86-ENU.exe goto END
if %1==WindowsXP-KB2761226-x86-ENU.exe goto END
echo %1
goto END

:NOPARAM
echo Approved updates:
if exist WindowsXP-KB2756822-x86-ENU.exe echo WindowsXP-KB2756822-x86-ENU.exe
if exist WindowsXP-KB2761226-x86-ENU.exe echo WindowsXP-KB2761226-x86-ENU.exe
echo.
echo Unapproved updates:
lfnfor on
for %%i in (WindowsXP-KB*.exe) do call %0 %%i

:END

Update

Another version that also lists missing files:


@echo off
set k1=KB2756822 KB2761226 KB2761465 KB2778344 KB2779030 KB2792100
set k2=KB2797052 KB2799329 KB2799494 KB2808735 KB2809289 KB2817183
if %1*==* goto NOPARAM

::Only list unapproved updates
for %%f in (%k1%) do if %1==WindowsXP-%%f-x86-ENU.exe goto END
for %%f in (%k2%) do if %1==WindowsXP-%%f-x86-ENU.exe goto END
echo %1
goto END

:NOPARAM
echo Approved updates:
for %%f in (%k1%) do if exist WindowsXP-%%f-x86-ENU.exe echo WindowsXP-%%f-x86-ENU.exe
for %%f in (%k2%) do if exist WindowsXP-%%f-x86-ENU.exe echo WindowsXP-%%f-x86-ENU.exe
echo.
echo Missing updates:
for %%f in (%k1%) do if not exist WindowsXP-%%f-x86-ENU.exe echo WindowsXP-%%f-x86-ENU.exe
for %%f in (%k2%) do if not exist WindowsXP-%%f-x86-ENU.exe echo WindowsXP-%%f-x86-ENU.exe
echo.
echo Unapproved updates:
lfnfor on
for %%i in (WindowsXP-KB*.exe) do call %0 %%i

:END

Edited by jumper
0

Share this post


Link to post
Share on other sites

Some of them are named IE8-WindowsXP-KB* so can I just do

for %%i in (WindowsXP-KB*.exe OR IE8-WindowsXP-KB*.exe) do call %0 %%i

?

Also "lfnfor on" is a non recognized command.

0

Share this post


Link to post
Share on other sites

>Some of them are named IE8-WindowsXP-KB* ...

Try

for %%i in (WindowsXP-KB*.exe IE8-WindowsXP-KB*.exe) do call %0 %%i

-or-

for %%i in (*WindowsXP-KB*.exe) do call %0 %%i

>Also "lfnfor on" is a non recognized command.

You can remove it. LFNFOR is only needed to enable long-file-name support in the FOR command on pre-NT versions of Windows and DOS.

This code should also work for all versions:


cd.>lfnfor.bat
lfnfor on
del lfnfor.bat

0

Share this post


Link to post
Share on other sites

allen2 has already pointed you with the obvious solution, FINDSTR /V.

As long as you have a local file listing Your updates, lets call it MyList.txt, then the following should suffice:

@FOR /F "TOKENS=*" %%# IN ('DIR/B *WINDOWSXP-KB*.EXE^|FINDSTR/VG:MYLIST.TXT') DO @ECHO/%%# IS NOT FROM MY LIST!

0

Share this post


Link to post
Share on other sites

allen2 has already pointed you with the obvious solution, FINDSTR /V.

As long as you have a local file listing Your updates, lets call it MyList.txt, then the following should suffice:

@FOR /F "TOKENS=*" %%# IN ('DIR/B *WINDOWSXP-KB*.EXE^|FINDSTR/VG:MYLIST.TXT') DO @ECHO/%%# IS NOT FROM MY LIST!

I found a quirk. If I have WindowsXP-KB2564958-X86-ENU.exe (capital x) in mylist.txt and have WindowsXP-KB2564958-x86-ENU.exe as my file then it flags it as not in the list. Any way to make it case insensitive? Strange because

WINDOWSXP-KB from the code is not the same as the updates which use WindowsXP-KB and they are not flagged.

Thanks.

EDIT: I found the /i switch, ( /I Specifies that the search is not to be case-sensitive.) but when I do FINDSTR/VGI, I get this.

D:\Profile\Desktop\WUD
FINDSTR: /G ignored
FINDSTR: /: ignored
FINDSTR: /u ignored
FINDSTR: /d ignored
FINDSTR: /a ignored
FINDSTR: /t ignored
FINDSTR: /. ignored
FINDSTR: /t ignored
FINDSTR: /t ignored
FINDSTR: Bad command line

EDIT2: Duh! I changed it to FINDSTR/VIG:updates.txt and all is well!

Edited by -X-
0

Share this post


Link to post
Share on other sites

Well done for trying different options, solving your problem and letting us know the outcome.

I didn't include the case insensitive switch because I figured you would have created MyList.txt directly from your master directory which I expected would contain file names in the correct case. I fgured that Microsoft would of course maintain that case throughout their various language versions of each update. A better option would be to have a MyList.txt which contains only the seven digit Knowledge Base numbers, KBnnnnnnn.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.