0

I have a problem with my batch code. I want to use substring for file name and add this string to another. When I use substring inside For loop my substring doesn't work. Variable str is empty. Could anybody help my? screen and code you can find below.

batch_screen

  echo on

set Subj="Docs nr  "

D: 
CD "\ANTEEO\INTEGRATION\BMHOUSING\out"
for /R  %%x in (*.csv) do (             
    CD  "D:\ANTEEO\INTEGRATION\BMHOUSING\"
    set str=%%~nx
    echo.%str%
    set str=%str:~0,10%
    echo.%str%
    set Subj=!%Subj%%str%!
    echo.%Subj%


    ) 
D. Turek
  • 1
  • 4
  • 2
    another one fell into the [delayed expansion trap](http://stackoverflow.com/a/30284028/2152082)... – Stephan Mar 17 '17 at 11:37
  • 1
    Besides Delayed Expansion, you have an error in this line: `set Subj=!%Subj%%str%!`. If you want to add both strings, then `set Subj=!Subj!!str!` is the right way with Delayed Expansion, or `call set Subj=%%Subj%%%%str%%` without. I suggest you to read [this answer](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Mar 17 '17 at 14:40

0 Answers0