2

My folder contain 5 sub folders: folder1_w, folder2, folder3_w, folder4, folder5.

I have to find out folders with name ending with "_w"

i tried this

@echo off

for /D %%i in (*) do (
    set name=%%i
    if %name:~-2% == _W ( 
        echo pass
    ) else (
        echo fail
    )   
)

pause
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Edit your question and add what did you have tried until now as code ! – Hackoo Oct 23 '19 at 17:25
  • 1
    you could just do `for /d %%i in (*_w) do echo %%i` hopefully "someone" does not complain that `for` loops are over complicating this. – Gerhard Oct 23 '19 at 17:50
  • thank you _/\_ Gerhard – sebastianedm Oct 23 '19 at 17:54
  • Your script lacks of [delayed variable expansion](https://ss64.com/nt/delayedexpansion.html), which is required when you write and read a variable in the same block of code. Though just using the pattern `*_w` instead of `*` would return only folders whose names end in `_w` without need of a variable and `if` conditions... – aschipfl Oct 23 '19 at 18:13
  • @Gerhard, please post that comment as an answer, to hopefully prevent the question from being closed as a delayed expansion duplicate. Thank you. – Compo Oct 23 '19 at 19:27

0 Answers0