Jump to content

Batch File!


Sh4dow

Recommended Posts


Here are the 3 words/acronyms that I am looking for:

FBI

Iowa

CIA

What I am trying to accomplish is if any two or three of these words/acronyms are in any type of file (doesn't have to be a txt file I just thought it would be easier) then I need to know the file name and location of the file. I have to search a server that has 300GB of data on it.

Link to comment
Share on other sites

Okay then, here is some complete code. (they are in the zip attached too!)

This will get every file containing all three of your search strings and open the results in your default text editor!

All you need to do is keep the two files together in the same directory, open the cmd prompt in that directory and type

  • get3 Drive:\Path

Don't forget to use quotes if Drive:\Path contains spaces!

get3.cmd

@ECHO OFF
IF %1 EQU "" ECHO You must provide a directory to check! e.g. %~0 C:\MyFiles && PAUSE && GOTO :EOF
IF NOT EXIST "%~1" ECHO The specified directory does not exist! && PAUSE && GOTO :EOF
SETLOCAL
SET STRS="%~dp0_3words.dat"
FOR /F "TOKENS=*" %%A IN ('FINDSTR /SIMP /G:%STRS% "%~1\*.*"') DO (
 CALL :chk "%%A" >NUL
 IF ERRORLEVEL 1 ECHO %%A >>"%~dp0all3.txt"
)
IF EXIST "%~dp0all3.txt" START "" /W "%~dp0all3.txt"
ENDLOCAL && GOTO :EOF
:chk
FOR /F "TOKENS=*" %%B IN ('TYPE %STRS%') DO (
 FINDSTR /SIMP "%%B" %1 || EXIT /B 0
)
EXIT /B 1

_3words.dat

\<FBI\>
\<Iowa\>
\<CIA\>

get3.zip

Link to comment
Share on other sites

Yzöwl

First off, thank you. That file works perfectly.

is there any chance at all that you would explain some of the lines of code that you wrote? It would greatly benefit myself and others

Link to comment
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.
×
×
  • Create New...