下面的代码通过合并来自不同目录的多个文件来创建单个输出文件。预期输出是正确的,但参数传递给%FileName%
的方式不正确。
来自CMD的示例日志:
C:\VP\TEST>type "C:\VP\APC\832I\810 - Copy.txt" 1>>"C:\VP\MACS_IN_PROCESS\WI832MCS.dat" The system cannot find the file specified. C:\VP\TEST>move "C:\VP\APC\832I\810 - Copy.txt" "C:\VP\MACS_IN_ARCHIVE\810 - Copy.txt" The system cannot find the file specified.
批处理文件代码:
@echo on
::This ensures the parameters are resolved prior to the internal variable
SetLocal EnableDelayedExpansion
SetLocal ENABLEEXTENSIONS
rem Get current date and time as local time.
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| %SystemRoot%\System32\Find.exe "."') do set dt=%%a
rem Reformat the date and time strong to wanted format.
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set "TimeStamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
rem Define name of the list file containing current date and time in name.
set "APC810_ListFile=APC810_FLIST_%TimeStamp%.lst"
set "APC832_ListFile=APC832_FLIST_%TimeStamp%.lst"
set "APC846_ListFile=APC846_FLIST_%TimeStamp%.lst"
set "APC855_ListFile=APC855_FLIST_%TimeStamp%.lst"
set "APC856_ListFile=APC856_FLIST_%TimeStamp%.lst"
rem Create file list
cd /D "C:\VP\APC\810I"
dir *.txt /A:-D /B /O:D >"C:\VP\TEST\%APC810_ListFile%"
cd /D "C:\VP\APC\832I"
dir *.txt /A:-D /B /O:D >"C:\VP\TEST\%APC832_ListFile%"
rem ====================== APC 810 ======================
rem Process each file in the list file.
cd /D "C:\VP\TEST"
for /F "delims=" %%F in ( %APC810_ListFile% ) do call :Process810 "%%F"
rem ====================== APC 832 ======================
rem Process each file in the list file.
cd /D "C:\VP\TEST"
for /F "delims=" %%F in ( %APC832_ListFile% ) do call :Process832 "%%F"
rem Exit batch file.
endlocal
goto :EOF
:Process810
set "FileName=%~1"
type "C:\VP\APC\810I\%FileName%" >>"C:\VP\MACS_IN_PROCESS\I810MCS.dat"
move "C:\VP\APC\810I\%FileName%" "C:\VP\MACS_IN_ARCHIVE\%FileName%"
:Process832
set "FileName=%~1"
type "C:\VP\APC\832I\%FileName%" >>"C:\VP\MACS_IN_PROCESS\WI832MCS.dat"
move "C:\VP\APC\832I\%FileName%" "C:\VP\MACS_IN_ARCHIVE\%FileName%"
答案 0 :(得分:0)
对不起,但你的帖子没有指明问题,你说明你的输出是正确的,但传递的参数不是。 (当然,如果您传递错误的参数,结果也会不正确)
这是一个非常快速的重写,它未经测试,可能包含错误。
@Echo Off
For /F "EOL=L" %%a In ('WMIC OS Get LocalDateTime') Do For %%b In (%%a
) Do Set "dt=%%~nb"
Set "Stamp=%dt:~,4%-%dt:~4,2%-%dt:~6,2%_%dt:~8,2%-%dt:~10,2%-%dt:~12,2%"
For %%a In (10 32 46 55 56) Do (
Dir/B/A-D/OD "C:\VP\APC\8%%aI\*.txt">"C:\VP\TEST\APC8%%a_FLIST_%Stamp%.lst"
For /F "UseBackQ Delims=" %%b In ("C:\VP\TEST\APC8%%a_FLIST_%Stamp%.lst"
) Do (Type "%%b">>"C:\VP\MACS_IN_PROCESS\I8%%aMCS.dat"
Move "%%b" "C:\VP\MACS_IN_ARCHIVE"))
...尝试一下,看看是否有帮助。