ECHO %%~nV%%~xV | FIND /I "%FSPEC2%" >NUL, why does FIND run so slow?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

ECHO %%~nV%%~xV | FIND /I "%FSPEC2%" >NUL, why does FIND run so slow?

#1 Post by nnnmmm » 27 Aug 2017 07:33

Code: Select all

@ECHO OFF
IF NOT "%OS%"=="Windows_NT" GOTO :EOF
REM *********************************************************************
SET ZLS=C:\ZLIST.ZLS
REM *********************************************************************
SET DRSPEC=C D E F G H I J K L M N O P Q R S T U V W X
SET FSPEC1=*GO*.*
SET FSPEC2=TA

TYPE NUL > %ZLS%

FOR %%U IN (%DRSPEC%) DO (

   IF EXIST %%U: (
      %%U:
      CD\

      FOR /F "TOKENS=*" %%V IN ('DIR "%FSPEC1%" /A-D /B /S') DO (

        REM ------------------------------------------
        REM ------------------------------------------
        ECHO %%~nV%%~xV | FIND /I "%FSPEC2%" >NUL
        REM ------------------------------------------
        REM ------------------------------------------

         IF NOT ERRORLEVEL 1 (
            ECHO "%%~fV">>%ZLS%
            ECHO %%~fV
            SET /A C1=C1+1
         )
      )
   )
)

ECHO ------------------------
ECHO numbers of files are %C1%
PAUSE



Code: Select all

AA=ECHO %%~nV%%~xV | FIND /I "%FSPEC2%" >NUL


without the line AA= a whole drive spectrum to find files with only one "SET FSPEC1=*GO*.*" takes about 30~40 seconds for maybe 400,000 files.

but with AA=, and with the 2nd "SET FSPEC2=TA" on, a search gets stuck on F: that has one directory that has many sub dir's with 90,000 files, and without F: in the search list, a 2 string search takes about 20 minutes, and i think that "| FIND" works too slow to be useful, and i like to know why it is, and maybe you can change my script to make it better, i need this 2 string search script.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: ECHO %%~nV%%~xV | FIND /I "%FSPEC2%" >NUL, why does FIND run so slow?

#2 Post by aGerman » 27 Aug 2017 08:48

FIND is an external executable (C:\Windows\System32\find.exe). Each time you call it a new process has to be scheduled and loaded by the operating system. The fact that you use it in a loop makes it worse. The fact that you execute it in a pipe makes it even worse because each side of a pipe is executed in a separate cmd.exe process.

Steffen

nnnmmm
Posts: 141
Joined: 26 Aug 2017 06:11

Re: ECHO %%~nV%%~xV | FIND /I "%FSPEC2%" >NUL, why does FIND run so slow?

#3 Post by nnnmmm » 27 Aug 2017 09:27

>external executable, must be scheduled and loaded, in a pipe in a separate cmd.exe
i see....

i put the script in an useless script directory, and i guess it is going to stay there

Post Reply