我遇到类型命令的问题,基本上需要连接相同标题的两个文件并将文件2数据附加到文件1中。直接执行批处理脚本时操作完成。但是,当从第三方工具(Informatica Cloud)调用批处理时,类型将作为重写。文件2数据覆盖文件1数据。有人可以帮我解决一下吗?
批处理脚本:
if "%time:~0,1%"==" " (set hh=0%time:~1,1%) else set hh=%time:~0,2%
set timestamp=%date:~10,4%%date:~4,2%%date:~7,2%%hh%%time:~3,2%%time:~6,2%
copy Sample_Transaction_Inbound_Veeva-i19.txt Sample_Transaction_Inbound_Veeva-i19_%timestamp%.txt
for /f "skip=1 delims=*" %%a in (F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\Sample_Order_Transaction_Inbound_Veeva-i19.txt) do (
echo %%a >>F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\REMOVE_HEADER\newfile.txt
)
type F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\REMOVE_HEADER\newfile.txt >> F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\Sample_Transaction_Inbound_Veeva-i19_%timestamp%.txt
REM echo "Yes" | copy /-Y F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\REMOVE_HEADER\*.txt "%TEMP%"
REM xcopy C:\newfile.txt C:\file.txt /y
del F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\REMOVE_HEADER\newfile.txt /f /q
F:\OTS_Veeva_CRM\Utilities\7z a -y Sample_Transaction_Inbound_Veeva-i19_%timestamp%.zip Sample_Transaction_Inbound_Veeva-i19_%timestamp%.txt
REM move Sample_Transaction_Inbound_Veeva-i19_%timestamp%.zip F:\OTS_Veeva_CRM\TargetFiles\ING2\Sample_Transaction_Inbound_Veeva-i19_%timestamp%.zip
copy F:\OTS_Veeva_CRM\TargetFiles\ING2\Sample_Transaction_Inbound_Veeva-i19_%timestamp%.zip F:\OTS_Veeva_CRM\TargetFiles\ING2_Archive\Sample_Transaction_Inbound_Veeva-i19_%timestamp%.zip
REM del F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL\Sample_Transaction_Inbound_Veeva-i19_%timestamp%.txt
答案 0 :(得分:1)
您的问题是默认的活动目录。由于某些文件引用不包含存储文件的文件夹(并且至少在发布的代码中)没有明确的pushd
或cd /d
,因此批处理时可能存在不同的默认文件夹从第三方工具调用文件,找不到一些文件。
因此,解决方案应该是确保选定的文件夹作为默认活动目录(在下面的示例中)或包含所有文件引用中的所有路径。
抱歉,我不得不重写它以遵循逻辑
@echo off
setlocal enableextensions disabledelayedexpansion
if "%time:~0,1%"==" " (set hh=0%time:~1,1%) else set hh=%time:~0,2%
set "timestamp=%date:~10,4%%date:~4,2%%date:~7,2%%hh%%time:~3,2%%time:~6,2%"
set "inputFile1=Sample_Transaction_Inbound_Veeva-i19.txt"
set "inputFile2=Sample_Order_Transaction_Inbound_Veeva-i19.txt"
set "combinedBaseName=Sample_Transaction_Inbound_Veeva-i19_%timestamp%"
set "combinedFile=%combinedBaseName%.txt"
set "zip=F:\OTS_Veeva_CRM\Utilities\7z.exe"
set "outputFolder=F:\OTS_Veeva_CRM\TargetFiles\ING2_Archive"
set "sourceFolder=F:\OTS_Veeva_CRM\TargetFiles\ING2\SMPL"
pushd "%sourceFolder%" && (
copy "%inputFile1%" "%combinedFile%"
>>"%combinedFile%" (
for /f "usebackq skip=1 delims=" %%a in ("%inputFile2%") do @echo(%%a
)
"%zip%" a -y "%outputFolder%\%combinedBaseName%.zip" "%combinedFile%"
popd
)