finding the files that have two strings matched?
Moderator: DosItHelp
finding the files that have two strings matched?
i need to find some files from c: to z: drives
i need to find the files that have two strings matched in the filename
SET S1=GO
SET S2=DER
a batch should find files like below
c:\abc\ddd\flamingo in a meandering swamp.txt
what would be the batch file that can do this?
i need to find the files that have two strings matched in the filename
SET S1=GO
SET S2=DER
a batch should find files like below
c:\abc\ddd\flamingo in a meandering swamp.txt
what would be the batch file that can do this?
Re: finding the files that have two strings matched?
Code: Select all
@echo off &setlocal
for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%i:\" (
2>nul dir /a-d /b /s "%%i\*go*der*.txt"
)
)
pause
I assume it will take ages.
Steffen
Re: finding the files that have two strings matched?
Code: Select all
type nul> m:\11.txt
@echo on &setlocal
for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%i:\" (
dir /a-d /b /s "%%i:\*go*ta*.*" >> m:\11.txt
dir /a-d /b /s "%%i:\*ta*go*.*" >> m:\11.txt
)
)
pause
what does "2>nul" mean in 2>nul dir /a-d /b /s "%%i\*go*der*.txt"?
it ran much much faster than using FIND and |
but i found that i could not cutomize this script without echo in it.
i need to import 11.txt to other application that requires few more strings need to be attached. because it can not tell if the datas are dirs or files or mixed.
i asked the quesiton wrongly in this thread, i will try some other time, thanks.
Last edited by nnnmmm on 28 Aug 2017 03:46, edited 1 time in total.
Re: finding the files that have two strings matched?
There are 3 default stream numbers 0 for stdin, 1 for stdout, and 2 for stderr. While 0 (with <) and 1 (with > and |) are used by default you need to define the 2 if you want to redirect error messages using > or >>.
I wrote the 2>nul in order to suppress error messages of the DIR command in case no files were found that match the pattern.
You can define several patterns.
Steffen
Whoops seems you edited your post.
I wrote the 2>nul in order to suppress error messages of the DIR command in case no files were found that match the pattern.
You can define several patterns.
Code: Select all
>"m:\11.txt" type nul
for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%i:\" (
pushd "%%i:\"
>>"m:\11.txt" dir /a-d /b /s "*go*ta*.*" "*ta*go*.*"
popd
)
)
Steffen
Whoops seems you edited your post.
Re: finding the files that have two strings matched?
Code: Select all
T="C:\UTI LITY\MOgoUSE SAMPLE RATtaE CHECKER.EXE"
T="C:\U TILITY\MOUSE SAMPLE atgoRATE CHECKER.TXT"
T="C:\UTILITY\XTGOLD\X tata go TG_VSAM.XTP"
the output data format is like above
T= must be present at each line
Re: finding the files that have two strings matched?
Just replace the DIR line with the following FOR /F loop.
Steffen
Code: Select all
for /f "delims=" %%j in ('dir /a-d /b /s "*go*ta*.*" "*ta*go*.*"') do >>"m:\11.txt" echo T="%%j"
Steffen
Re: finding the files that have two strings matched?
why couldnt i come up with this without using | and FIND
your line was totally good, i added
CMD /U /C echo T="%%j" >>11.sss to be even more perfect.
| and find.exe dont even use cache, even the 2nd run still takes half an hour
while
this
takes few senconds for the 2nd and 3rd run even with different inputs
thanks for a help
your line was totally good, i added
CMD /U /C echo T="%%j" >>11.sss to be even more perfect.
| and find.exe dont even use cache, even the 2nd run still takes half an hour
while
this
Code: Select all
for /f "delims=" %%j in ('dir /a-d /b /s "*go*ta*.*" "*ta*go*.*"') do >>"m:\11.txt" echo T="%%j"
takes few senconds for the 2nd and 3rd run even with different inputs
thanks for a help
Re: finding the files that have two strings matched?
CMD /U /C
means you create a new cmd.exe process for each line you want to output.
You may want to run the whole FOR loop in a cmd.exe process with Unicode support.
Steffen
means you create a new cmd.exe process for each line you want to output.
You may want to run the whole FOR loop in a cmd.exe process with Unicode support.
Code: Select all
cmd /q /u /c "for /f "delims=" %%j in ('dir /a-d /b /s "*go*ta*.*" "*ta*go*.*"') do >>"m:\11.txt" echo T="%%j""
Steffen
Re: finding the files that have two strings matched?
Code: Select all
AA=
SET FSPEC="*%FS1%*%FS2%*.*" "*%FS2%*%FS1%*.*"
TYPE NUL > %ZLS%
SET CC=0
FOR %%U IN (%DRSPEC%) DO (
IF EXIST "%%U:\" (
ECHO %%U:
PUSHD "%%U:\"
CMD /Q /U /C (
FOR /F "DELIMS=" %%V IN ('DIR %FSPEC% /A-D /B /S') DO (
ECHO T="%%V">>%ZLS%
SET /A CC=CC+1
)
)
POPD
)
)
BB=
SET FSPEC="*%FS1%*%FS2%*.*" "*%FS2%*%FS1%*.*"
TYPE NUL > %ZLS%
SET CC=0
FOR %%U IN (%DRSPEC%) DO (
IF EXIST "%%U:\" (
ECHO %%U:
PUSHD "%%U:\"
CMD /U /C /Q (
FOR /F "DELIMS=" %%V IN ('DIR %FSPEC% /A-D /B /S') DO (
ECHO T="%%V">>%ZLS%
SET /A CC=CC+1
)
)
POPD
)
)
DD=
SET FSPEC="*%FS1%*%FS2%*.*" "*%FS2%*%FS1%*.*"
TYPE NUL > %ZLS%
SET CC=0
FOR %%U IN (%DRSPEC%) DO (
IF EXIST "%%U:\" (
ECHO %%U:
PUSHD "%%U:\"
FOR /F "DELIMS=" %%V IN ('DIR %FSPEC% /A-D /B /S') DO (
CMD /Q /U /C ECHO T="%%V">>%ZLS%
SET /A CC=CC+1
)
POPD
)
)
AA=doesnt make unicode output
BB=doesnt make unicode output and causes error that seems big. CMD /U /C /Q i put /Q at the end, why would it make a difference?
DD=works, makes unicode output
I didnt use the "" that you surrounded them, because i used () to put the commands in a seperate lines.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: finding the files that have two strings matched?
nnnmmm wrote:AA=doesnt make unicode output
BB=doesnt make unicode output and causes error that seems big. CMD /U /C /Q i put /Q at the end, why would it make a difference?
DD=works, makes unicode output
I really don't understand what these symbols are supposed to represent. Are they separate scripts?
nnnmmm wrote:I didnt use the "" that you surrounded them, because i used () to put the commands in a seperate lines.
Yeah... that's not valid batch syntax.
Have you considered Visual Basic?
Re: finding the files that have two strings matched?
Code: Select all
SET DRSPEC=C D E G H I J K L M N O P Q R S T U V W
SET FS1=TA
SET FS2=GO
SET ZLS=M:\11.TXT
SET FSPEC=*%FS1%*%FS2%*.*" "*%FS2%*%FS1%*.*
nothing really fancy, they were just straight variable claims
too wordy, so re-edited
Re: finding the files that have two strings matched?
Code: Select all
AA=
FOR /F "DELIMS=" %%V IN ('DIR %FSPEC% /A-D /B /S') DO (
CMD /Q /U /C ECHO T="%%V">>%ZLS%
SET /A CC+=1
)
BB=
CMD /Q /U /C "FOR /F "DELIMS=" %%V IN ('DIR %FSPEC% /A-D /B /S') DO ECHO T="%%V">>%ZLS%"
FOR /F %%D IN ('TYPE %ZLS% ^| FIND ":" /C') DO ( SET CC=%%D )
this is my conclusion
there may not be a way to make in this form CMD /Q /U /C () so that you could put commands in different lines
Code: Select all
DD=
CMD /U /C ( .... or CMD /U /C "&( .... or CMD /U /C "& ... and etc
FOR /F "DELIMS=" %%V IN ('DIR %FSPEC% /A-D /B /S') DO (
ECHO T="%%V">>%ZLS%
SET /A CC+=1
)
...
i think i am done with this script, thanks for a help. i just need to test AA= and BB= for a while.