Windows批处理脚本:在diff命令中使用变量不起作用

时间:2017-03-17 15:20:47

标签: batch-file diff gnu

我是批处理脚本的新手。我的脚本很简单。 到目前为止,我已经获得了代码,可以设置2个动态的2个变量文件名(每次运行脚本时可能会有所不同)。

现在我想在" diff"中使用这些变量。命令。

我可能需要使用GNU Diffutils

目前的剧本:

:Variables
SET FolderPath=H:\Marketing\Website\DB Files\CSV Outputs

@echo on
echo Upload Item Master diff to FTP
FOR /F "delims=|" %%I IN ('DIR "%FolderPath%\*.csv" /B /O:D') DO SET NewestFile=%%I
FOR /F "delims=|" %%J IN ('DIR "%FolderPath%\*.csv" /B /O:-D') DO SET OldestFile=%%J

echo Newest file %NewestFile%
echo Oldest file %OldestFile%

diff --unchanged-line-format= --old-line-format= --new-line-format='%L' %OldestFile% %NewestFile% >%FolderPath%\DiffOut\IM-diff.csv

目前的输出是:

    .....    
    H:\>echo Newest file DB Item Master table 17-03-17.csv
    Newest file DB Item Master table 17-03-17.csv

    H:\>echo Oldest file DB Item Master table 28-02-17.csv
    Oldest file DB Item Master table 28-02-17.csv

    H:\>diff --unchanged-line-format= --old-line-format= --new-line-format='OldestFileNewestFileFolderPath\DiffOut\IM-diff.csv
    diff: missing operand after `--new-line-format='OldestFileNewestFileFolderPath\DiffOut\IM-diff.csv'
    diff: Try `diff --help' for more information.

我需要脚本能够将变量文件名放在命令中,所以:

H:\>diff --unchanged-line-format= --old-line-format= --new-line-format='"DB Item Master table 28-02-17.csv" "DB Item Master table 17-03-17.csv" "H:\Marketing\Website\DB Files\CSV Outputs\DiffOut\IM-diff.csv"

1 个答案:

答案 0 :(得分:0)

解决

谢谢,添加额外的%使其成功!

非常感谢Squashman

(BTW>输出问题与其他事情有关 - 我把它排序好了)