Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 批处理在循环内部重新初始化全局变量,并在循环外部使用它_Variables_Batch File_Expansion_Delay - Fatal编程技术网

Variables 批处理在循环内部重新初始化全局变量,并在循环外部使用它

Variables 批处理在循环内部重新初始化全局变量,并在循环外部使用它,variables,batch-file,expansion,delay,Variables,Batch File,Expansion,Delay,首先我是初学者。我有多个文件在目录中,其名称包含日期,我需要找到哪个文件是最新的(只需要日期)。这就是我目前所拥有的 set currentYear=2013 set logDate=0 set tempLogDate=0 set fileName2=0 setlocal enabledelayedexpansion for /f "delims=" %%a in ('dir /a-d/b/s "%logDirectory2%"^|findstr /riv "^.*\\[^\\]*%now%[

首先我是初学者。我有多个文件在目录中,其名称包含日期,我需要找到哪个文件是最新的(只需要日期)。这就是我目前所拥有的

set currentYear=2013
set logDate=0
set tempLogDate=0
set fileName2=0
setlocal enabledelayedexpansion

for /f "delims=" %%a in ('dir /a-d/b/s "%logDirectory2%"^|findstr /riv "^.*\\[^\\]*%now%[^\\]*$"') do (
set fileName2=%%a
call set fileName2=!fileName2!:!currentYear!=%%
set tempLogDate=%currentYear%!fileName2:~0,4!
if !tempLogDate! GTR %logDate% ( set logDate=%tempLogDate% )
)

echo !logDate!
问题是循环内变量没有得到更改,提前感谢


*我更改了一些代码,但仍然没有解决…:(多么糟糕的一周开始

为了在循环中更改变量时访问变量的值,您需要调用
enabledelayedexpansion
)然后,您需要使用!varname!来访问
更改的
值;`%varname%访问解析时间值,也就是说,在循环开始之前初始变量值

感谢您的响应,我确实使用了您的提示,但仍然一样,我认为我需要彻底学习VA的基本知识在执行此操作之前,请先执行RIABLE扩展,无论如何,谢谢,感谢它的解决,谢谢@peterwright为您提供的指针