1

I need some batch-noob-treatment.

I'm trying to rename all the files in a folder and I'm slowly getting there, but although I got the step right with some google help, I would like to know what I'm doing.

Here is my code until now:

@ECHO OFF
setlocal enabledelayedexpansion

set a="dir /b"
FOR /F "delims=" %%i IN (' %a% ') DO (
set str=%%i
set str=!str:~1!
echo !str!
)

Anything else I put inside the for loop brings out strange results. I know the enabledelayedexpansion and ! are somehow connected and make this work, but how is the inside of a for loop different from the normal commands in batch, so that special syntax is needed?

What goes wrong if I put in code like that:

@ECHO OFF

set a="dir /b"
FOR /F "delims=" %%i IN (' %a% ') DO (
set i=%i:~1%
echo %%i
)
SugarOnBacon
  • 115
  • 7
  • 1
    Maybe [this](http://stackoverflow.com/a/30177832/2861476) could help – MC ND Aug 31 '15 at 19:45
  • Your link looks like it could work for me. I'll need some time to read it all and figure it out. Sorry I didn't see the question, but it's title is different. :/ – SugarOnBacon Aug 31 '15 at 20:01

1 Answers1

1

set i=%i:~1% is wrong as there is a gigantic difference between for loop control variables (e.g. %i) versus environment variables (e.g. %i% or %str%) and appropriate manipulation with them:

Further resources (required reading, incomplete):

JosefZ
  • 28,460
  • 5
  • 44
  • 83