【发布时间】:2022-12-08 00:24:12
【问题描述】:
是否可以在一个.txt文件中批量写入多个Variables? 我想制作一个随机密码生成器,您首先必须说出密码必须有多少个字符,然后生成密码并将其放入 .txt 文件中
我的想法是,首先(在您说出密码应该有多长之后)生成一个随机数(开始时为 1、2 或 3(1 = a、2 = b、3 = c))。然后看选择了哪个数字然后搜索对应的字母写入txt文档,直到和你开头说的一样多的字符。
看起来像这样:
@echo off
:main
cls
set /p anz=How many characters?:
goto rand
:rand
set /a letter=%random% %%3
goto test
:test
if %letter%==1 goto 1
if %letter%==2 goto 2
if %letter%==3 goto 3
:1
if %anz%==0 goto finish
set /p print=a
set /a anz-=1
goto printin
:2
if %anz%==0 goto finish
set /p print=b
set /a anz-=1
goto printin
:3
if %anz%==0 goto finish
set /p print=c
set /a anz-=1
goto printin
:printin
echo %print% > Your_Password.txt <--- Here does the letter get written in the .txt file
goto rand
:finish
echo finish
goto main
但它只写 .txt 文件中的最后一个字母
一开始我只用 a, b, c 做了,以后我想添加整个字母表
我是一批新手,首先收集我的第一次经验
【问题讨论】:
-
>覆盖文本文件的内容,>>附加到文本文件的末尾。此外,echo添加了一个换行符,因此每个字母都将在其自己的单独行上,除非你这样做<nul set /p "=%print%" >Your_password.txt。此外,%random% %% 3将返回 0 到 2 之间的数字,因此您需要相应地调整您的数字或将+1粘贴到该等式的末尾。 -
<nul set /p "=%print%" >Your_password.txt 是什么意思,我需要将它设置在该行后面还是用该行替换它?
-
做
<nul set /p "=%print%" >>Your_password.txt而不是echo %print% > Your_Password.txt -
现在在 Your_Password.txt 中写着:ECHO ist ausgeschaltet (OFF)。你知道谁来解决这个问题吗?
标签: batch-file