0
我对批处理脚本相当陌生。我的脚本只是简单的。 到目前为止,我已经得到了代码设置2个变量的2个文件名是动态的(每次脚本运行时都可能不同)。Windows批处理脚本:在diff命令中使用变量不起作用
现在我想在“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"
可能需要在新的行格式百分号一倍。请记住,百分比符号具有特殊含义。所以它将'%L'%'看作要展开的变量名称。因此,将'%L'改为'%% L' – Squashman
这是设计。 1>表示它将标准输出重定向到文件。您无法使cmd.exe不能将>>扩展为1>。 – Squashman
用代码删除你的评论并编辑你的问题。很难阅读评论。 – Squashman