You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用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%

:: 仅当历史文件不存在时写入固定标题
if not exist History.txt echo This is the History > History.txt
:: 追加写入本次搜索的账号名
echo %s% >> History.txt

逻辑说明

  • 新增的if not exist History.txt语句会先判断当前目录下是否已经存在历史记录文件
  • 只有文件不存在(即脚本第一次运行)时,才会执行创建文件并写入顶部标题的操作
  • 后续运行脚本时,因为历史文件已经存在,会直接跳过写标题的步骤,仅追加新的搜索账号名,不会清空之前保存的历史记录

内容的提问来源于stack exchange,提问作者user17293338

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 15:15:03