Search code examples
windowsbatch-filecmdinformaticainformatica-powercenter

Type command issue


I have an issue with type command that basically needs to concatenate two files of same header and put file 2 data appended in file 1. The operation is done fine while executing the batch script directly. But when calling the batch from a third party tool (Informatica Cloud), type works as rewrite. The file 2 data overwrites file 1 data. Can someone help me a way out?

Batch script:

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

Solution

  • Your problem is the default active directory. As some file references does not include the folder where the file is stored and (at least in the posted code) there is no explicit pushd or cd /d, probably, there is a different default folder when the batch file is called from the third party tool and some files are not found.

    So the solution should be to ensure that the adecuated folder is selected as default active directory (in the sample below) or include all the paths in all file references.

    Sorry, i had to rewrite it to follow the logic

    @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
        )