如何使用cmd在文本文件的顶部添加一个句子

How to add a sentence at the top of a text file using cmd

这是项目

@echo off
set /p s=Enter the name of the account you want to search for:

start https://www.facebook.com/%s%
start https://www.instagram.com/%s%
start https://www.tiktok.com/@%s%
start https://twitter.com/%s%
start https://story.snapchat.com/@%s%

echo %s% >> History.txt

我想在文本文件的顶部放置一个标题

如果你这样写代码

@echo off
set /p s=Enter the name of the account you want to search for:

start https://www.facebook.com/%s%
start https://www.instagram.com/%s%
start https://www.tiktok.com/@%s%
start https://twitter.com/%s%
start https://story.snapchat.com/@%s%
echo This is the History > History.txt
echo %s% >> History.txt

它不会保存用户名,因为每次它都会删除所有内容然后添加一个标题

我希望他只在第一次创建文件时添加标题

尝试像这样的代码:

@echo off
Title Searching account
set /p s=Enter the name of the account you want to search for:
If Not Exist "%~dp0History.txt" (echo This is the History)>"%~dp0History.txt"
If Exist "%~dp0History.txt" (echo %s%)>>"%~dp0History.txt"

start https://www.facebook.com/%s%
start https://www.instagram.com/%s%
start https://www.tiktok.com/@%s%
start https://twitter.com/%s%
start https://story.snapchat.com/@%s%