text: Q:
  
  Echo first three characters of filenames in CMD Windows
  
  for /r %g in (*.html) do echo %~ng:~0,3%
  This does not work. I have tested a lot, but could not find the answer.
  How do you echo the first three characters of all HTML-filenames?
  
  A:
  
  @ECHO OFF
  SETLOCAL
  
  :: first way:
  
  FOR /r %%g IN (*.html) DO (
   SET "var=%%~ng"
   CALL ECHO %%var:~0,3%%
  )
  
  pause
  
  :: second way:
  
  SETLOCAL ENABLEDELAYEDEXPANSION
  FOR /r %%g IN (*.html) DO (
   SET "var=%%~ng"
   ECHO !var:~0,3!
  )
  
  GOTO :EOF
  
  The fundamental issue is that substringing must be applied to an ordinary environment variable, not to a metavariable.
  
  