Solved bold the file name based on a specific search string result

October 16, 2012 at 07:33:40
Specs: Windows XP
I need to search hundreds of files for a specific text string and if found bold the file name. All the file names are numbers ex. 121016.134423

See More: bold the file name based on a specific search string result

Report •

✔ Best Answer
October 22, 2012 at 06:56:32
Here simple as possible as you requested (not filtered) the file names containing the string you input are in bold, when the result is parsed into a variable the bold seems to go.
@echo off & setlocal enabledelayedexpansion
cd c:\test\call\system\format
set string=
set /P string=Enter string to search for:
findstr /C:"%string%" *
pause > nul
exit /b



#1
October 16, 2012 at 14:49:38
///Edit just updated,
Here you go:
@echo off & setlocal enabledelayedexpansion
set string=?
set /P string=What string do you want to search for?
for /f "delims=" %%a in ('findstr /C:"%string%" *') do (
set result=!result!%%a
cls
)
set filter=%result:*:=%
set result=!result:%filter%=!
set file=%result:~0,-1%
echo filename:%file%
pause > nul

Report •

#2
October 17, 2012 at 10:17:59
Thank you for the post,
I tried the run the code but I can not get it to complete. I may be entering the search string incorrectly. I am searching for a string like this "CALL_SYS". and this search is being run in a directory containing 100,000 files the directory structure is "c:\test\call\system\format.

Report •

#3
October 17, 2012 at 12:04:38
Will take a look.

Report •

Related Solutions

#4
October 17, 2012 at 18:24:17
maybe use colon to delimit the filename in the findstr output:
::===== begin script BOLD.BAT
@echo off
pushd c:\test\call\system\format
(for /f "tokens=1 delims=:" %%a in ('findstr /c:%1 *') do echo %%a)>list
popd
::===== end script

Note: usage in this case is: BOLD "searchstring"
searchstring must be quoted. If you want case-ignore, just add '/i' to the findstr arguments.


Report •

#5
October 18, 2012 at 03:50:34
I could not get the last changes to work so I went back to the first batch code and it now stops at the first file name after you enter the search string. If you hit enter to try and continue it closes the dos window. Thank you

Report •

#6
October 18, 2012 at 07:47:28
i stupidly put a space between /c and %1. should be:
findstr /c:%1
might give that a whirl. edited my post to reflect the change and to fix another dumb mistake i made: echo off>list
since "list" is not in the current directory.
List resides in the target directory.

Report •

#7
October 22, 2012 at 03:10:20
I tried the code with the latest changes and it still hangs up. I get the following error " FINDSTR: Argument missing after /c"

Thank you


Report •

#8
October 22, 2012 at 03:41:04
I also tried the code from thebest123456 and this code stops at the first file and hangs. If you hit enter you exit the code.

Thank you


Report •

#9
October 22, 2012 at 06:56:32
✔ Best Answer
Here simple as possible as you requested (not filtered) the file names containing the string you input are in bold, when the result is parsed into a variable the bold seems to go.
@echo off & setlocal enabledelayedexpansion
cd c:\test\call\system\format
set string=
set /P string=Enter string to search for:
findstr /C:"%string%" *
pause > nul
exit /b


Report •

#10
October 22, 2012 at 07:21:20
This is great so far, I just ran the code from thebest123456 and it did search and found the required string. Next I need the file name to change to bold when the string is found.
@echo off & setlocal enabledelayedexpansion
set string=
set /P string=Enter string to search for:
findstr /C:"%string%" *
pause > nul
exit /b

Thank you


Report •

#11
October 22, 2012 at 07:34:52
?
The filename(s) is/are bold at least on my comp.

Report •

#12
October 22, 2012 at 09:37:33
Hi thebest123456, I have been rerunning the code and the file name is still not bold after finding the string. I also tried to have the code just check a specific directory (I changed the C: to the correct path) and I noticed that it checked the files but did not find the string. I am running windows XP I didn't know if this made a difference.

Thank You for your help so far.


Report •

#13
October 22, 2012 at 10:50:34
lol, the /c is the findstr command if you want to change the directory use cd location at the beginning of the file. Anyway it's late here, will work on it tomorrow, (all files found containing x string will be parsed into a .txt file).

Report •

#14
October 22, 2012 at 11:19:47
Thanks for the explanation I was able to change the code to look in a specific dir and it does find the string now.
The reason I have to keep the file name the same is because a separate program matches file 1 name to a file 2 name in a different directory (both files have the same name but different contents) . I thought that bolding the file name would be the best method to quickly recognize the important files in a list.
Also the directory that this batch file will be operating in will have new files added every 30 minutes. I was going to add this batch file to a scheduler to run every 30 min also. Do you think it will have time to process all of the files each time or should it have the capability of recognizing only the new files? The directory normally has several hundred thousand files.

Thank You for your Help


Report •

#15
October 25, 2012 at 06:47:57
Hi Thebest123456, could you post a copy of the final batch code you are running that works fine for you. I am thinking that maybe I am not running the complete code because there was the first iteration then the simplified code. THANKS

Report •

Ask Question