For circulation get the file name, the use of temporary variables

@echo off 
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /b Test*.txt') do (
set temp=%%a
set tempname=!temp:~0,4!
if not exist !tempname!.txt (
  echo hello >> !tempname!.txt
 )
)

If you need to be in the For the variable assignment:setlocal enabledelayedexpansion,否则变量赋值是空。同时如果需要使用for中的临时变量需要使用"!"。

Guess you like

Origin www.cnblogs.com/zhongqingshen/p/12083050.html