Batch file 批量写入文件时新行回车

Batch file 批量写入文件时新行回车,batch-file,Batch File,我有一个程序,它接受一个参数文件名。 我还有一个文件,其中存储了正在传递的所有文件名列表。 现在,每当传递一个文件名时,我想将其与回车符一起添加到文件名列表中 例如: Names.txt _______________ Sample1.txt Sample2.txt Sample3.txt 等等 我已经试过了,但无法将值放入新行。 你能帮忙吗 echo on @REM parameter 1 = path and file to copy SET saveloc=E:\Tem

我有一个程序,它接受一个参数文件名。 我还有一个文件,其中存储了正在传递的所有文件名列表。 现在,每当传递一个文件名时,我想将其与回车符一起添加到文件名列表中

例如:

Names.txt
_______________
Sample1.txt
Sample2.txt
Sample3.txt
等等

我已经试过了,但无法将值放入新行。 你能帮忙吗

    echo on


@REM parameter  1 = path and file to copy


SET saveloc=E:\Temp\201405\receivedfiles.txt

SET "FileList="
For /F "Delims=" %%A In (%saveloc%) Do (
    SETLOCAL EnableDelayedExpansion
    Call SET FileList=%%FileList%%%%A&echo.
)
Set FileList=%FileList%%1%

echo %FileList%>%saveloc%

将输出重定向到文件时,
将覆盖目标文件。使用
>
附加到文件。

如果我这样做,它不会向文件写入任何内容。@user788312,是否将文件作为第一个参数传递给批处理文件?如果您传递了该文件,并且您有权写入日志文件,那么它应该将信息写入日志文件。如何调用批处理文件?testnewline.cmd C:\Temp\sample。txt@user788312,对我来说,这是有效的。请删除
@echo off
,查看调用批处理时执行的操作。
@echo off
    :: arg1 = name of file. If not present, leave the batch file
    if "%~1"=="" exit /b 1

    :: Where to save the information
    set "saveloc=E:\Temp\201405\receivedfiles.txt"

    :: Append the argument to the log
    >> "%saveloc%" echo(%~1