我有一个接受参数文件名的程序。 我还有一个文件,我存储了所有正在传递的文件名列表。 现在,当传递文件名时,我想将它添加到文件名列表以及回车。
示例:
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%
答案 0 :(得分:0)
@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
将输出重定向到文件>
时会覆盖目标文件。使用>>
附加到文件。