8
8
83349 M2018-02-21 19:05:08
cmd/bat
83349 M, 2018-02-21 19:05:08

How to output part of the path correctly?

You need to sort through all the folders. If there is a test.js file in the folder. You need to take the part of the path after the initial one and use it further. And the problem is that it is not possible to display this path.
If it does, then this is the path used in the last step of the loop.
Nesting can be any, but it seems that the condition normally works, only the output of this path remains. How to implement it?

for /r "G:\test\batch" /d %%i in (*) do (
  Set namePath=%%i
    IF EXIST %%i\test.js (
        Set "namePath=%namePath:G:\test\batch=%"
        Set "namePath=%namePath:\=/%"
        echo "namePath : %namePath%"
    )
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-02-21
@f1o007

In general, you are doing everything right, except for a few nuances.
Here is an example:

@echo off
SetLocal EnableDelayedExpansion
set "begindir=G:\test\batch"

for /r "%begindir%" %%i in (*) do (
  Set "namePath=%%i"
  set "namePath=!namePath:%begindir%=!"
  echo.!namePath!
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question