No idea how to distinguish "client name" from "not a client name".
If you mean "directory names" where each client has a directory, then:
@Echo Off
setlocal enableDelayedExpansion
pushd
for /d /r C:\test %%x in (.) do (
ECHO [ !DATE! !TIME! ] Executing %%x ...
CD %%~dpx
CALL _Test.cmd
IF NOT ERRORLEVEL 1 (
ECHO [ !DATE! !TIME! ] Successful!
)
)
popd
Notes:
pushd/popd bracket saves the current directory and restores after for loop.
for /d /r means directories, recursive
Target "." means "all" - if you have a mask to apply, put that mask here.
cd %%~dpx is simply shorter than your version.
if errorlevel 0 is always true under normal circumstances. if errorlevel n means "if errorlevel is n or greater than n". cmd can be forced to set errorlevel negative, but it's a contrived situation.
" i need to run _Test.cmd for only particular clients like client24,client15,client40."
Now if you'd said that to start off with....
@Echo Off
setlocal enabledelayedexpansion
pushd
for /f "delims=" %%x in (yourfileofclients.txt) do if exist "c:\test\%%~x\." (
ECHO [ !DATE! !TIME! ] Executing %%x ...
CD "c:\test\%%~x"
CALL _Test.cmd
IF NOT ERRORLEVEL 1 (
ECHO [ !DATE! !TIME! ] Successful!
)
)
popd