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

Posted zhongqingshen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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中的临时变量需要使用"!"。

以上是关于For循环获取文件名,使用临时变量的主要内容,如果未能解决你的问题,请参考以下文章