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-loop:
@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
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)ugnx*:if exist "O:\ugnx100\nx10.24\....\fsnac3\"ugii"\ugraf.exe" echo/O:\ugnx100\nx10.24\...\fsnac3\"ugii"\ugraf.exefor /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.cmd /Q, then try again, or place@symbols before commands/blocks…