For循环获取文件名,使用临时变量

@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
 )
)

如果需要在For中进行变量赋值:setlocal enabledelayedexpansion,否则变量赋值是空。同时如果需要使用for中的临时变量需要使用"!"。

猜你喜欢

转载自www.cnblogs.com/zhongqingshen/p/12083050.html
今日推荐