2014-10-08 123 views
0

我有一個類型命令的問題,基本上需要連接兩個相同頭文件,並將文件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 

回答

1

你的問題是默認的Active Directory。由於某些文件引用不包括存儲文件的文件夾,並且(至少在發佈的代碼中)沒有明確的pushdcd /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 
    ) 
+0

由於MC ND !!完美的一個! – 2014-10-08 09:21:05

+0

您能否在這裏詳細說明覆制聲明的用法?我不清楚它是如何工作的。但是我的工作已經完成了,再次感謝! – 2014-10-08 09:24:07

+1

@SFDC_GEEK,和原來的代碼一樣。組合文件由第一個輸入文件(複製爲組合文件)和第二個輸入文件(用'for'處理以刪除第一行)生成, – 2014-10-08 09:25:48