Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如何使批处理脚本在每次执行时都编写新的文本文件?_Batch File - Fatal编程技术网

Batch file 如何使批处理脚本在每次执行时都编写新的文本文件?

Batch file 如何使批处理脚本在每次执行时都编写新的文本文件?,batch-file,Batch File,我有一个批处理脚本。我希望批处理脚本应覆盖现有文件,但不应覆盖for循环条目 PFB批处理文件的内容: for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do call ec2-describe-snapshots --filter "volume-id=%%s">>%EC2_HOME%\Snapshots.txt 我希望每次执行脚本时都有一个新的文本文件。而且我希望它不会覆盖以前for循环变量的条目 如果您只使用一个箭头,谢谢 &

我有一个批处理脚本。我希望批处理脚本应覆盖现有文件,但不应覆盖for循环条目

PFB批处理文件的内容:

for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do call ec2-describe-snapshots --filter "volume-id=%%s">>%EC2_HOME%\Snapshots.txt
我希望每次执行脚本时都有一个新的文本文件。而且我希望它不会覆盖以前for循环变量的条目


如果您只使用一个箭头,谢谢

>
它将覆盖文件,或者如果使用多个箭头

>>
它将附加到文件中

因此,对于第一个for循环使用>,对于后续循环使用>>,您可以尝试

    rem Remove file contents
    break > %EC2_HOME%\Snapshots.txt

    for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do (
        call ec2-describe-snapshots --filter "volume-id=%%s" >> %EC2_HOME%\Snapshots.txt
    )
或者


但是我还想在第一次执行脚本时删除文本文件?我该怎么做呢。意思是我想把delete语句放在脚本的第一行。
(
    for /f "tokens=2" %%s in (%EC2_HOME%\Volumes.txt) do (
        call ec2-describe-snapshots --filter "volume-id=%%s"
    )
) > %EC2_HOME%\Snapshots.txt