Plink in batch script

310 views Asked by At
@ECHO OFF

SET filename=autoexec.bat

FOR /R C:\ %%a IN (\) DO (
   IF EXIST "%%a\%filename%" (

      SET fullpath=%%a%filename%
      GOTO break
   )
)
:break

ECHO %fullpath%

Will give me a path with \\ in between. How to come up with only \ in between?

2

There are 2 answers

3
unclemeat On BEST ANSWER

It's because you are doing:

FOR /R C:\ %%a IN (\) DO ...

Try instead, replacing the \ with *;

FOR /R C:\ %%a IN (*) DO ...

The value in the brackets is the file set that you want to loop through, an asterisk specifies ALL.

0
cure On
set filename=autoexec.bat
for /f %%i in ('dir \*%filename% /b /s') do set fullpath=%%i