【发布时间】:2014-02-07 12:21:25
【问题描述】:
我有以下代码,它从“AX 副本”中获取最后修改的文件,并将其与“反射副本”中的最后修改文件进行比较。然后输出 Error 的差值。
我需要输出副本与“AX 副本”中的输入文件同名。我已经使用了一些东西来再次声明文件名并将其分配给输出。但是我有一个问题,在下面的代码中删除它时,它使用最旧的文件名。
请有人调整代码,使输出副本与“AX 副本”文件夹中的输入具有相同的名称。我的代码是:
@echo off
cd /d C:\Users\Important Structure\Development\AX copy
for /f %%a in ('dir /b /o-d /a-d /tw') do (set latest=%%a)
setlocal enableextensions disabledelayedexpansion
call :getLatestFileInFolder "C:\Users\Important Structure\Development\AX copy" latestC
call :getLatestFileInFolder "C:\Users\Important Structure\Development\Reflex copy" latestD
if not defined latestC ( echo NO File in C & exit /b )
if not defined latestD ( echo NO File in D & exit /b )
for /f "tokens=1,*" %%a in (
'diff "%latestC%" "%latestD%" ^| findstr /r /c:"^<" /c:"^>"'
) do (
>> "C:\Users\Important Structure\Development\Error\%latest%" echo(%%b
)
endlocal
exit /b
:getLatestFileInFolder folderToSearch variableToReturn
setlocal
set "folder=%~1" & if not defined folder set "folder=%cd%"
set "latest="
pushd "%folder%"
for /f "tokens=*" %%a in ('dir /b /o-d /a-d /tw 2^>nul') do (set "latest=%%~fa" & goto :latestFileFound)
:latestFileFound
popd
endlocal & set "%~2=%latest%" & goto :eof
【问题讨论】:
-
我想你只需要使用
%LatestC%代替%Latest% -
您好,我试过了,但由于没有生成文件,所以无法正常工作
标签: variables batch-file cmd filenames