Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:12:50+00:00 2026-06-09T01:12:50+00:00

Ok, I have been playing around with this for a while and am getting

  • 0

Ok, I have been playing around with this for a while and am getting no where. I need to pull the KB number out from a line.

The issue i am having is that some of the KB numbers are 6 characters and some are 7, and can’t seem to find a way that will work to error detect the two.

The Two types of errors this makes is as follows

The First one should only have been displayed 6 characts so it added the extra “-” at the end.

x64 KB890830-   2012\MS12-000\WinSec-KB890830-006-P58310-Windows-KB890830-x64-V4.9.exe 

While the second error shows the random “_” because it uses the first KB shown not the second.

ia64    KB_942288   2012\MS12-000\WinSec-KB_942288-007-P58312-WindowsServer2003-KB942288-v4-ia64.exe

EDIT
Batch File So Far

@ECHO OFF
SETLOCAL enableDelayedExpansion

IF EXIST Export.csv DEL Export.csv
FOR /F "tokens=*" %%I in ('dir /s /b *.*') DO CALl:Generate "%%I"
pause

:Generate
SETLOCAL
IF "%~x1" NEQ ".exe" (
    If "%~x3" NEQ ".msu" (
        GOTO:EOF
    )
)
CALL:FindArchitecture %1
CALL:FindKB %1
CALL:PathFix %1
ECHO %Architecture%,%KB%,%FilePath%>>Export.csv
CALL:Cleanup
ENDLOCAL
GOTO:EOF


:FindArchitecture
ECHO %1 | FINDSTR "x64"
IF "%ERRORLEVEL%"=="0"  (
    SET Architecture=x64
    SET Count+=1
)
ECHO %1 | FINDSTR "x86"
IF "%ERRORLEVEL%"=="0" (
    SET Architecture=x86
    SET Count+=1
)

ECHO %1 | FINDSTR "ia64"
IF "%ERRORLEVEL%"=="0" (
    SET Architecture=ia64
    SET Count+=1
)

IF "%Count%" GTR "1" (
    SET Architecture=Error
)
SET Count=0
GOTO:EOF

:FindKB
set KBNum="%~1"
set "KBNum=!KBNum:*-KB=!"
ECHO !KBNum!|findstr /I /E /R /c:"-KB[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" >nul 
SET "KB=KB!KBNum:~0,7!"
IF "%KB%" NEQ "" GOTO:EOF
ECHO !KBNum!|findstr /I /E /r /c:"-KB[0-9][0-9][0-9][0-9][0-9][0-9]" >nul
SET "KB=KB!KBNum:~0,6!"
GOTO:EOF

:PathFix
set Path_to_convert=%~1
set Reference_path=%~dp0
set FilePath=!Path_to_convert:*%Reference_path%=!
GOTO:EOF

:Cleanup
SET KBNum=
SET KB=
SET Count=
SET Architecture=
set InstallerPath=
set PathRemoval=
set Path=
GOTO:EOF
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:12:51+00:00Added an answer on June 9, 2026 at 1:12 am

    OK – siginificant edit after seeing comments from Ken White and the OP.

    I’m not sure if you need this, but FINDSTR with a regular expression can validate that the line has the pattern: “-KB” followed by 7 digits, followed by “-“.

    echo somestring|findstr /r /c:"-KB[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-" >nul
    

    Then use substitution to remove everything from the beginning through “KB-“.

    Then use FINDSTR to verify that the first 7 remaining characters are digits. If not, then loop back and replace up to the next “-KB”, etc.

    Then you just need to take the first remaining 7 characters.

    @echo off
    :parseVal
    setlocal enableDelayedExpansion
    set val="%~1"
    echo !val!|findstr /r /c:"-KB[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-" >nul || (
      echo Invalid format - KB value not found
      exit /b
    )
    :parseVal2
    set "val=!val:*-KB=!"
    echo !val!|findstr /brc:"[0-9][0-9][0-9][0-9][0-9][0-9][0-9]-" >nul || goto :parseVal2
    set "val=KB!val:~0,7!"
    echo val=!val!
    exit /b
    

    EDIT

    I’m not sure what you did to accept the 6 digit numbers, but the following regex expressions will work with numbers of any length.

    For the 1st regex: findstr /rc:"-KB[0-9]*-"
    For the 2nd regex: findstr /brc:"[0-9]*-"

    Then you can use either of the following to extract out the number when you don’t know the length:

    for /f "delims=-" %%A in ("!val!") do set "val=KB%%A"
    

    or

    set val=KB%val:-=&REM %"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing around with this for a couple of hours and have come
I have been playing around with the Silverlight progressbar a while and no matter
I have been playing around with this and wanted to get a second opinion.
I have been playing around with GTK since a couple of days now,while going
I have been playing around with code for a while now, and I have
Have been playing around with instruments with not much luck in figuring out how
I have been playing around with Google Apps Script today and I am trying
I have been playing around a bit with a fairly simple, home-made search engine,
I have been playing around with the MVP pattern using winforms for the last
I have been playing around with the Rhino ETL library and really like the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.