Solved **Question Regarding Writing to Text Files**

September 28, 2012 at 17:23:46
Specs: Windows 7
Hello, It's me again. I was wondering if someone could explain to me how to properly write more text to a file that already has text in it without erasing what is already in it. Right now, I have a script that loops 264 times creating a new value for the variable %va% every time. I want it to ECHO this value to a text file with spaces in between each value once for every time it goes through the loop. The variable %va% is always a single character. I want it to echo these 264 characters total to a text file in a table of 12 lines 24 colums (which equals 264 characters) Here is my script:

set loopc1=264
set /a rand0=%random% %% 29+1
IF /I %rand0%==1 set va=^!
IF /I %rand0%==2 set va=^@
IF /I %rand0%==3 set va=^#
IF /I %rand0%==4 set va=^$
IF /I %rand0%==5 set va=^_
IF /I %rand0%==6 set va=^&
IF /I %rand0%==7 set va=^*
IF /I %rand0%==8 set va=^(
IF /I %rand0%==9 set va=^)
IF /I %rand0%==10 set va=^+
IF /I %rand0%==11 set va=^-
IF /I %rand0%==12 set va=^=
IF /I %rand0%==13 set va=^[
IF /I %rand0%==14 set va=^]
IF /I %rand0%==15 set va=^\
IF /I %rand0%==16 set va=^{
IF /I %rand0%==17 set va=^}
IF /I %rand0%==18 set va=^|
IF /I %rand0%==19 set va=^;
IF /I %rand0%==20 set va=^'
IF /I %rand0%==21 set va=^:
IF /I %rand0%==22 set va=^"
IF /I %rand0%==23 set va=^<
IF /I %rand0%==24 set va=^>
IF /I %rand0%==25 set va=^?
IF /I %rand0%==26 set va=^,
IF /I %rand0%==27 set va=^.
IF /I %rand0%==28 set va=^/
IF /I %rand0%==29 set va=^^
ECHO character ^%va%
ECHO ^%va% > c:\Users\%USERNAME%\Desktop\FALLOUTgame\wordgentest.txt
GOTO loopcontrol
set /a loopc1=%loopc1%-1
IF /I %loopc1% GTR 0 GOTO genchars

See More: **Question Regarding Writing to Text Files**

Report •

September 28, 2012 at 19:27:24
Suggest you study output redirection here

In the script you posted GoTo loopcontrol and :loopcontrol are superfluous, execution will automatically drop to the next command when %va% has been written to the file.

Please come back & tell us if your problem is resolved.

Report •

September 28, 2012 at 20:39:31
✔ Best Answer
I think you will find that

12 * 24 = 288
264 / 24 = 11
264 / 12 = 22

Well anyway.......

@echo off
set char_set=!@#$_^&*()+-=[]\{}^|;':^"^<^>?,./^^

set out_file="Test.txt"
if exist %out_file% (
    echo(%out_file% exists!
    Echo([Y]es or [A]ll to overwrite file, [N]o to append to file.
    echo(Press enter after selection
copy /-y nul %out_file% > nul

set char_max=264
set col_max=24
set col_cnt=0

SetLocal EnableDelayedExpansion

for /l %%a in (1 1 !char_max!) do (
    set /a char_ran=!random! %% 29
    for %%b in (!char_ran!) do (
        set char_line=!char_set:~%%b,1! !char_line!
    set /a col_cnt+=1
    if !col_cnt!==!col_max! (
        set char_line=!char_line:~0,-1!
        >> !out_file! echo(!char_line!
        set char_line=
        set col_cnt=0

if not !col_cnt!==0 (
    >> !out_file! echo(!char_line!

Report •

September 30, 2012 at 12:31:56
OMG! I have been trying to solve this for 3 weeks!! this is exactly what I need!

Report •

Related Solutions

Ask Question