I am trying to make a batch script to rename files in a directory. All the filenames are stored in a text file and I am reading them in a script. File names are the updates released by microsoft. Since the filenames downloaded are not in a patterned format, I am having difficulty to rename hundreds of files. for eample if a file name is - windows6.1-KB1234567 update for_IE10 for RCE.msu
I want to rename it to KB1234567
I got success in scripting the renaming where KB number is inside brackets by using () in delims but I am stuck at getting KB numbers from above mentioned kind of files. Somewhere KB numbers are between hyphens and somewhere between spaces.
Also the ERRORLEVEL starts giving faulty returncode when I try to use findstr or find command. It returns zero even if the KB word is found or not.
So I am looking for a quick fix for this requirement.
EDIT1: The script I used for finding KB numbers surrounded by brackets
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=()" %%x in (D:\updates\list1.txt) do (
echo %%y
EDIT2: The code I am trying is:-
for /f "tokens=1-10 delims=-" %%a in (D:\updates\list2.txt) do (
echo %%c | find /I "kb"
echo Errorlevel for matching KB in %%c is- %ERRORLEVEL%
)
The file list2.txt contains(the example file names):
ie11-windows6.1-kb123456-x86_d43434342344ef.msu
IE8-windows6.0-KB234567-X86.msu
windows6.1-kb345678-x86_cae45678123_nov_17.msu
Currently I am targeting the filenames having hyphens. Once done I will script for filenames containing spaces. The EDIT2 script I created for just testing the errorlevel of find command. It will split words separated by hyphens and check for presence of a hyphen. But no matter what I do, even if it finds the match of KB word in separate words or not, ErrorLevel returned is zero. For simplicity right now I am just giving script which will pick third word and find kb in it. The third filename has no KB it the 3rd word, but the errorlevel for that filename is also zero.
Thanks
Kriss