1

I'm trying to find out ugraf.exe files from mapped drive. Below command loops through all folders on current drive to find file - ugraf.exe .

For /R %A In (ugraf.exe)Do @Echo %~dpnxA

I want to find the ugraf.exe in folders starting from ugnx* and existing only in ugii folder.

O:\ugnxxxxx\...\wntx64\kits\ugii\ugraf.exe

Could anyone please help me?

4
  • 2
    for /D %A in ("O:\ungx*") do pushd "%~A" && ((for /D /R %B in ("ugii") do if exist "%~B\ugraf.exe" echo/%~B\ugraf.exe) & popd) Commented Jun 30, 2020 at 13:35
  • @aschipfl, getting lines as ouput, seems like looping through all folders of 1st ugnx* : if exist "O:\ugnx100\nx10.24\....\fsnac3\"ugii"\ugraf.exe" echo/O:\ugnx100\nx10.24\...\fsnac3\"ugii"\ugraf.exe Commented Jun 30, 2020 at 13:49
  • Is the issue that in for /D /R %B in ("ugii"), the string within the parentheses is supposed to be a glob? If you change any one of the characters to a ?, it should fix that, (e.g. u?ii), however, you'd have to be sure that the character you change doesn't then match another none required directory too. Commented Jun 30, 2020 at 15:35
  • You are also receiving the command echos; start the Command Prompt as cmd /Q, then try again, or place @ symbols before commands/blocks… Commented Jun 30, 2020 at 16:41

2 Answers 2

2

Unless there are a lot of large directories in the root of O: whose names do not begin with the string ugnx, it seems as if it would be simpler to just search for the file, then check its output for ugnx and ugii directories in the returned path string:

@"%__AppDir__%where.exe" /R "O:\." "ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$"

You could even do that with the Dir command, instead of using where.exe:

@Dir /B /S /A:-D "O:\ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$"

If you wanted to capure it from a :

@For /F "Delims=" %%G In ('""%__AppDir__%where.exe" /R "O:\." "ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$""') Do @Echo %%G

Or using the Dir command instead of where.exe

@For /F "Delims=" %%G In ('"Dir /B /S /A:-D "%%G\ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$""') Do @Echo %%G

If the directories in the root of O: on your ugnx* directory level could be large or many, then just pass that from an initial For /D loop:

@For /D %%G In ("O:\ungx*") Do @For /F "Delims=" %%H In ('""%__AppDir__%where.exe" /R "%%G" "ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$""') Do @Echo %%H

Or using the Dir command instead of where.exe

@For /D %%G In ("O:\ungx*") Do @For /F "Delims=" %%H In ('"Dir /B /S /A:-D "%%G\ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$""') Do @Echo %%G

Or a For /F loop:

@For /F "Delims=" %%G In ('Dir /B /S /A:D "O:\ungx*" 2^>NUL') Do @For /F "Delims=" %%H In ('""%__AppDir__%where.exe" /R "%%G" "ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$""') Do @Echo %%H

And once again, using Dir, instead of where.exe:

@For /F "Delims=" %%G In ('Dir /B /S /A:D "O:\ungx*" 2^>NUL') Do @For /F "Delims=" %%H In ('"Dir /B /S /A:-D "%%G\ugraf.exe" 2>NUL | "%__AppDir__%findstr.exe" /I /R "^O:\\ugnx*\\ugii\\ugraf\.exe$""') Do @Echo %%H
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, there are tons of files and folders on O drive. I'm running all 3 solutions.
The number of files and folders on the O: drive is not what I said, @Experimenter. I was deliberately specific, the issue, (speed), would only be if there were a lot of large trees in the root of O: adjacent to O:\ugnx*. The time would be wasted going through those trees first. I have therefore added an additional For /D and For /F option for those scenarios. Feel free to test them all for speed. You could also try replacing "%__AppDir__%where.exe" /R "%%G" "ugraf.exe" with Dir /B /S /A:-D "%%G\ugraf.exe" in those examples to see if it's quicker for you too, (answer updated).
1

You can pipe your results with findstr commands:

... | findstr /I "O:\ugn" | findstr /I "ugii\ugraf.exe"

The /I stands for case insensitivity.
The findstr /I "O:\ugn" checks that the main directory is indeed "ugnxxxxx".
The findstr /I "ugii\ugraf.exe" makes sure you only get the ones in the "ugii" directory.

1 Comment

The \ and . characters are special in findstr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.