请帮我看看下面的bat代码有什么问题,(获取指定目录下的指定类型文件,将文件名保存到变量中)
下面代码中执行后,只有temp[0]有值,预期应该是201203191105.backup,但是实际结果值是201203191109.backup,@ECHOoffSET...
下面代码中执行后,只有temp[0]有值,预期应该是201203191105.backup,但是实际结果值是201203191109.backup,
@ECHO off
SET extension=".backup"
SET number=0
cd %~dp0\backup
FOR %%C IN (*%extension%) DO (
SET temp[%number%]=%%C
SET number=(%number%+1)
)
cd %~dp0
echo %temp[0]%
echo %temp[1]%
echo %temp[2]%
echo %temp[3]%
echo %temp[4]%
PAUSE
-----------------
backup文件夹中有:201203191105.backup ~201203191109.backup ,5个文件 展开
@ECHO off
SET extension=".backup"
SET number=0
cd %~dp0\backup
FOR %%C IN (*%extension%) DO (
SET temp[%number%]=%%C
SET number=(%number%+1)
)
cd %~dp0
echo %temp[0]%
echo %temp[1]%
echo %temp[2]%
echo %temp[3]%
echo %temp[4]%
PAUSE
-----------------
backup文件夹中有:201203191105.backup ~201203191109.backup ,5个文件 展开
展开全部
SET number=(%number%+1)
这个有问题,应该
set /a number+=1
还有前面应该加变量延迟
setlocal enabledelayedexpansion
@ECHO off
setlocal enabledelayedexpansion
SET extension=".backup"
SET number=0
cd %~dp0\backup
FOR /r %%C IN (*%extension%) DO (
SET temp[!number!]=%%C
SET /a number+=1
)
cd %~dp0
echo %temp[0]%
echo %temp[1]%
echo %temp[2]%
echo %temp[3]%
echo %temp[4]%
PAUSE
这个有问题,应该
set /a number+=1
还有前面应该加变量延迟
setlocal enabledelayedexpansion
@ECHO off
setlocal enabledelayedexpansion
SET extension=".backup"
SET number=0
cd %~dp0\backup
FOR /r %%C IN (*%extension%) DO (
SET temp[!number!]=%%C
SET /a number+=1
)
cd %~dp0
echo %temp[0]%
echo %temp[1]%
echo %temp[2]%
echo %temp[3]%
echo %temp[4]%
PAUSE
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询