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

Time:11-10

This is the project

@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

I want to put a title at the top of the text file

If you make the code like this

@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

It will not save usernames, because every time it deletes everything and then adds a title

I want him to add the title only the first time, when he creates the file

CodePudding user response:

Try like this code :

@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%
  • Related